From fe0b0559818b3d70c97c9081ec633927550892a8 Mon Sep 17 00:00:00 2001
From: nickago <ngonella@calpoly.edu>
Date: Tue, 11 Aug 2015 12:19:23 -0700
Subject: Added server side validation of jpegs as images

---
 web/react/components/file_upload.jsx | 6 ------
 1 file changed, 6 deletions(-)

(limited to 'web/react/components/file_upload.jsx')

diff --git a/web/react/components/file_upload.jsx b/web/react/components/file_upload.jsx
index b90fa4fd3..0638e7109 100644
--- a/web/react/components/file_upload.jsx
+++ b/web/react/components/file_upload.jsx
@@ -101,9 +101,6 @@ module.exports = React.createClass({
                 for (var i = 0; i < items.length; i++) {
                     if (items[i].type.indexOf('image') !== -1) {
                         var ext = items[i].type.split('/')[1].toLowerCase();
-                        if (ext === 'jpeg') {
-                            ext = 'jpg';
-                        }
 
                         if (Constants.IMAGE_TYPES.indexOf(ext) < 0) {
                             continue;
@@ -124,9 +121,6 @@ module.exports = React.createClass({
                         var file = items[i].getAsFile();
 
                         var ext = items[i].type.split('/')[1].toLowerCase();
-                        if (ext === 'jpeg') {
-                            ext = 'jpg';
-                        }
 
                         if (Constants.IMAGE_TYPES.indexOf(ext) < 0) {
                             continue;
-- 
cgit v1.2.3-1-g7c22


From 51e63ced936802a49b049a36022ddf6b45c17f6a Mon Sep 17 00:00:00 2001
From: nickago <ngonella@calpoly.edu>
Date: Tue, 11 Aug 2015 13:07:16 -0700
Subject: Cosmetic refactoring

---
 web/react/components/file_upload.jsx | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

(limited to 'web/react/components/file_upload.jsx')

diff --git a/web/react/components/file_upload.jsx b/web/react/components/file_upload.jsx
index 0638e7109..c1fab669c 100644
--- a/web/react/components/file_upload.jsx
+++ b/web/react/components/file_upload.jsx
@@ -7,6 +7,13 @@ var ChannelStore = require('../stores/channel_store.jsx');
 var utils = require('../utils/utils.jsx');
 
 module.exports = React.createClass({
+    displayName: 'FileUpload',
+    propTypes: {
+        onUploadError: React.PropTypes.func,
+        getFileCount: React.PropTypes.func,
+        onFileUpload: React.PropTypes.func,
+        onUploadStart: React.PropTypes.func
+    },
     getInitialState: function() {
         return {requests: {}};
     },
@@ -21,7 +28,7 @@ module.exports = React.createClass({
         // This looks redundant, but must be done this way due to
         // setState being an asynchronous call
         var numFiles = 0;
-        for(var i = 0; i < files.length; i++) {
+        for (var i = 0; i < files.length; i++) {
             if (files[i].size <= Constants.MAX_FILE_SIZE) {
                 numFiles++;
             }
@@ -51,11 +58,11 @@ module.exports = React.createClass({
             var request = client.uploadFile(formData,
                 function(data) {
                     var parsedData = $.parseJSON(data);
-                    this.props.onFileUpload(parsedData['filenames'], parsedData['client_ids'], channelId);
+                    this.props.onFileUpload(parsedData.filenames, parsedData.client_ids, channelId);
 
                     var requests = this.state.requests;
-                    for (var i = 0; i < parsedData['client_ids'].length; i++) {
-                        delete requests[parsedData['client_ids'][i]];
+                    for (var i = 0; i < parsedData.client_ids.length; i++) {
+                        delete requests[parsedData.client_ids[i]];
                     }
                     this.setState({requests: requests});
                 }.bind(this),
@@ -100,9 +107,9 @@ module.exports = React.createClass({
             if (items) {
                 for (var i = 0; i < items.length; i++) {
                     if (items[i].type.indexOf('image') !== -1) {
-                        var ext = items[i].type.split('/')[1].toLowerCase();
+                        var testExt = items[i].type.split('/')[1].toLowerCase();
 
-                        if (Constants.IMAGE_TYPES.indexOf(ext) < 0) {
+                        if (Constants.IMAGE_TYPES.indexOf(testExt) < 0) {
                             continue;
                         }
 
@@ -110,7 +117,7 @@ module.exports = React.createClass({
                     }
                 }
 
-                var numToUpload = Math.min(Constants.MAX_UPLOAD_FILES - self.props.getFileCount(channelId), numItems);
+                var numToUpload = Math.min(Constants.MAX_UPLOAD_FILES - self.props.getFileCount(ChannelStore.getCurrentId()), numItems);
 
                 if (numItems > numToUpload) {
                     self.props.onUploadError('Uploads limited to ' + Constants.MAX_UPLOAD_FILES + ' files maximum. Please use additional posts for more files.');
@@ -155,11 +162,11 @@ module.exports = React.createClass({
                         var request = client.uploadFile(formData,
                             function(data) {
                                 var parsedData = $.parseJSON(data);
-                                self.props.onFileUpload(parsedData['filenames'], parsedData['client_ids'], channelId);
+                                self.props.onFileUpload(parsedData.filenames, parsedData.client_ids, channelId);
 
                                 var requests = self.state.requests;
-                                for (var i = 0; i < parsedData['client_ids'].length; i++) {
-                                    delete requests[parsedData['client_ids'][i]];
+                                for (var i = 0; i < parsedData.client_ids.length; i++) {
+                                    delete requests[parsedData.client_ids[i]];
                                 }
                                 self.setState({requests: requests});
                             },
-- 
cgit v1.2.3-1-g7c22

