Преглед изворни кода

attachment.limit responses available capacity

yusueketk пре 7 година
родитељ
комит
be8088ff22
2 измењених фајлова са 5 додато и 15 уклоњено
  1. 1 1
      config/env.dev.js
  2. 4 14
      src/server/routes/attachment.js

+ 1 - 1
config/env.dev.js

@@ -1,7 +1,7 @@
 module.exports = {
   NODE_ENV: 'development',
   FILE_UPLOAD: 'mongodb',
-  GRIDFS_LIMIT: 20000000,
+  GRIDFS_LIMIT: 200000,
   // MATHJAX: 1,
   ELASTICSEARCH_URI: 'http://localhost:9200/growi',
   HACKMD_URI: 'http://localhost:3010',

+ 4 - 14
src/server/routes/attachment.js

@@ -107,28 +107,18 @@ module.exports = function(crowi, app) {
   };
 
   /**
-   * @api {get} /attachments.limit Limit amount of uploaded file with GridFS
+   * @api {get} /attachments.limit get available capacity of uploaded file with GridFS
    * @apiName AddAttachments
    * @apiGroup Attachment
-   *
-   * @apiParam {int} size
    */
   api.limit = async function(req, res) {
-    let isUploadable = true;
     if (process.env.FILE_UPLOAD !== 'mongodb') {
-      return res.json(ApiResponse.success({isUploadable: isUploadable}));
+      return res.json(ApiResponse.success({usableCapacity: Infinity}));
     }
     else {
-      const uploadFileSize = req.query.size;
       const usingFilesSize = await fileUploader.getCollectionSize();
-
-      if (process.env.GRIDFS_LIMIT >= +uploadFileSize + usingFilesSize) {
-        return res.json(ApiResponse.success({isUploadable: isUploadable}));
-      }
-      else {
-        isUploadable = false;
-        return res.json(ApiResponse.success({isUploadable: isUploadable}));
-      }
+      const usableCapacity = +process.env.GRIDFS_LIMIT - usingFilesSize;
+      return res.json(ApiResponse.success({usableCapacity: usableCapacity}));
     }
   };