yusueketk 7 лет назад
Родитель
Сommit
e10f5b0bef
2 измененных файлов с 7 добавлено и 3 удалено
  1. 2 2
      src/client/js/components/PageEditor.js
  2. 5 1
      src/server/routes/attachment.js

+ 2 - 2
src/client/js/components/PageEditor.js

@@ -116,8 +116,8 @@ export default class PageEditor extends React.Component {
    * @param {any} files
    * @param {any} files
    */
    */
   async onUpload(file) {
   async onUpload(file) {
-    const res = await this.props.crowi.apiGet('/attachments.limit', {_csrf: this.props.crowi.csrfToken, size: file.size});
-    if (!res.isUploadable) {
+    const res  = await this.props.crowi.apiGet('/attachments.limit', {_csrf: this.props.crowi.csrfToken});
+    if (file.size > res.usableCapacity) {
       throw new Error('mongoDB for file uploading reaches the limit');
       throw new Error('mongoDB for file uploading reaches the limit');
     }
     }
     else {
     else {

+ 5 - 1
src/server/routes/attachment.js

@@ -130,7 +130,7 @@ module.exports = function(crowi, app) {
    * @apiParam {String} page_id
    * @apiParam {String} page_id
    * @apiParam {File} file
    * @apiParam {File} file
    */
    */
-  api.add = function(req, res) {
+  api.add = async function(req, res) {
     var id = req.body.page_id || 0,
     var id = req.body.page_id || 0,
       path = decodeURIComponent(req.body.path) || null,
       path = decodeURIComponent(req.body.path) || null,
       pageCreated = false,
       pageCreated = false,
@@ -139,6 +139,10 @@ module.exports = function(crowi, app) {
     debug('id and path are: ', id, path);
     debug('id and path are: ', id, path);
 
 
     var tmpFile = req.file || null;
     var tmpFile = req.file || null;
+    const usingFilesSize = await fileUploader.getCollectionSize();
+    if (tmpFile.size > usingFilesSize) {
+      throw new Error('mongoDB for file uploading reaches the limit');
+    }
     debug('Uploaded tmpFile: ', tmpFile);
     debug('Uploaded tmpFile: ', tmpFile);
     if (!tmpFile) {
     if (!tmpFile) {
       return res.json(ApiResponse.error('File error.'));
       return res.json(ApiResponse.error('File error.'));