Просмотр исходного кода

Merge branch 'master' into feat/tag-form-with-typeahead

yusuketk 7 лет назад
Родитель
Сommit
0557214ff0

+ 21 - 22
src/client/js/components/PageEditor/Editor.jsx

@@ -28,7 +28,7 @@ export default class Editor extends AbstractEditor {
     this.dragLeaveHandler = this.dragLeaveHandler.bind(this);
     this.dropHandler = this.dropHandler.bind(this);
 
-    this.getDropzoneAccept = this.getDropzoneAccept.bind(this);
+    this.getAcceptableType = this.getAcceptableType.bind(this);
     this.getDropzoneClassName = this.getDropzoneClassName.bind(this);
     this.renderDropzoneOverlay = this.renderDropzoneOverlay.bind(this);
   }
@@ -104,8 +104,24 @@ export default class Editor extends AbstractEditor {
     }
   }
 
+  /**
+   * get acceptable(uploadable) file type
+   */
+  getAcceptableType() {
+    let accept = 'null'; // reject all
+    if (this.props.isUploadable) {
+      if (!this.props.isUploadableFile) {
+        accept = 'image/*'; // image only
+      }
+      else {
+        accept = ''; // allow all
+      }
+    }
+
+    return accept;
+  }
+
   pasteFilesHandler(event) {
-    const dropzone = this.refs.dropzone;
     const items = event.clipboardData.items || event.clipboardData.files || [];
 
     // abort if length is not 1
@@ -116,11 +132,8 @@ export default class Editor extends AbstractEditor {
     for (let i = 0; i < items.length; i++) {
       try {
         const file = items[i].getAsFile();
-        // check type and size
-        if (file != null
-            && pasteHelper.fileAccepted(file, dropzone.props.accept)
-            && pasteHelper.fileMatchSize(file, dropzone.props.maxSize, dropzone.props.minSize)) {
-
+        // check file type (the same process as Dropzone)
+        if (file != null && pasteHelper.isAcceptableType(file, this.getAcceptableType())) {
           this.dispatchUpload(file);
           this.setState({ isUploading: true });
         }
@@ -158,20 +171,6 @@ export default class Editor extends AbstractEditor {
     this.setState({ isUploading: true });
   }
 
-  getDropzoneAccept() {
-    let accept = 'null'; // reject all
-    if (this.props.isUploadable) {
-      if (!this.props.isUploadableFile) {
-        accept = 'image/*'; // image only
-      }
-      else {
-        accept = ''; // allow all
-      }
-    }
-
-    return accept;
-  }
-
   getDropzoneClassName() {
     let className = 'dropzone';
     if (!this.props.isUploadable) {
@@ -243,7 +242,7 @@ export default class Editor extends AbstractEditor {
         <Dropzone
           ref="dropzone"
           disableClick
-          accept={this.getDropzoneAccept()}
+          accept={this.getAcceptableType()}
           className={this.getDropzoneClassName()}
           acceptClassName="dropzone-accepted"
           rejectClassName="dropzone-rejected"

+ 1 - 13
src/client/js/components/PageEditor/PasteHelper.js

@@ -32,22 +32,10 @@ class PasteHelper {
    * @param {*} file
    * @param {*} accept
    */
-  fileAccepted(file, accept) {
+  isAcceptableType(file, accept) {
     return file.type === 'application/x-moz-file' || accepts(file, accept);
   }
 
-  /**
-   * transplanted from react-dropzone
-   * @see https://github.com/react-dropzone/react-dropzone/blob/master/src/utils/index.js
-   *
-   * @param {*} file
-   * @param {number} maxSize
-   * @param {number} minSize
-   */
-  fileMatchSize(file, maxSize, minSize) {
-    return file.size <= maxSize && file.size >= minSize;
-  }
-
 }
 
 // singleton pattern

+ 6 - 0
src/server/service/config-loader.js

@@ -122,6 +122,12 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    TYPES.NUMBER,
     default: Infinity,
   },
+  MONGO_GRIDFS_TOTAL_LIMIT: {
+    ns:      'crowi',
+    key:     'gridfs:totalLimit',
+    type:    TYPES.NUMBER,
+    default: Infinity,
+  },
   SAML_USES_ONLY_ENV_VARS_FOR_SOME_OPTIONS: {
     ns:      'crowi',
     key:     'security:passport-saml:useOnlyEnvVarsForSomeOptions',

+ 2 - 6
src/server/service/file-uploader/gridfs.js

@@ -62,13 +62,9 @@ module.exports = function(crowi) {
       return { isUploadable: false, errorMessage: 'File size exceeds the size limit per file' };
     }
 
-    // skip checking if env var is undefined
-    if (process.env.MONGO_GRIDFS_TOTAL_LIMIT == null) {
-      return { isUploadable: true };
-    }
-
     const usingFilesSize = await getCollectionSize();
-    if (usingFilesSize + uploadFileSize > +process.env.MONGO_GRIDFS_TOTAL_LIMIT) {
+    const gridfsTotalLimit = crowi.configManager.getConfig('crowi', 'gridfs:totalLimit');
+    if (usingFilesSize + uploadFileSize > gridfsTotalLimit) {
       return { isUploadable: false, errorMessage: 'MongoDB for uploading files reaches limit' };
     }