Sfoglia il codice sorgente

PageEditor send size of upload file to server when upload file in page

yusueketk 7 anni fa
parent
commit
d3c67bd98a

+ 6 - 0
src/client/js/components/PageEditor.js

@@ -115,6 +115,12 @@ export default class PageEditor extends React.Component {
    * @param {any} files
    */
   onUpload(file) {
+    this.props.crowi.apiGet('/attachments.limit', {
+      _csrf: this.props.crowi.csrfToken, size: file.size
+    })
+    .then((res) => {
+      console.log(res.isUploadabe);
+    });
     const endpoint = '/attachments.add';
 
     // create a FromData instance

+ 16 - 0
src/server/routes/attachment.js

@@ -106,6 +106,22 @@ module.exports = function(crowi, app) {
     });
   };
 
+  /**
+   * @api {get} /attachments.limit Limit amount of uploaded file with GridFS
+   * @apiName AddAttachments
+   * @apiGroup Attachment
+   *
+   * @apiParam {int} size
+   */
+  api.limit = function(req, res) {
+    const uploadFileSize = req.query.size;
+    const isUploadable = true;
+    if (process.env.FILE_UPLOAD !== 'mongodb') {
+      return res.json(ApiResponse.success({isUploadable: isUploadable}));
+    }
+    return res.json(ApiResponse.success({isUploadable: isUploadable}));
+  };
+
   /**
    * @api {post} /attachments.add Add attachment to the page
    * @apiName AddAttachments

+ 1 - 0
src/server/routes/index.js

@@ -212,6 +212,7 @@ module.exports = function(crowi, app) {
   app.get( '/_api/attachments.list'   , accessTokenParser , loginRequired(crowi, app, false) , attachment.api.list);
   app.post('/_api/attachments.add'    , uploads.single('file'), accessTokenParser, loginRequired(crowi, app) ,csrf, attachment.api.add);
   app.post('/_api/attachments.remove' , accessTokenParser , loginRequired(crowi, app) , csrf, attachment.api.remove);
+  app.get( '/_api/attachments.limit' , accessTokenParser , loginRequired(crowi, app) , csrf, attachment.api.limit);
 
   app.get( '/_api/revisions.get'      , accessTokenParser , loginRequired(crowi, app, false) , revision.api.get);
   app.get( '/_api/revisions.ids'      , accessTokenParser , loginRequired(crowi, app, false) , revision.api.ids);