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

appear toastr.error when error of exceeding the limit occurs in front end

yusueketk пре 7 година
родитељ
комит
20c68c58d1

+ 11 - 1
src/client/js/components/PageEditor.js

@@ -10,6 +10,8 @@ import Editor from './PageEditor/Editor';
 import Preview from './PageEditor/Preview';
 import scrollSyncHelper from './PageEditor/ScrollSyncHelper';
 import { promise } from 'when';
+import * as toastr from 'toastr';
+
 
 export default class PageEditor extends React.Component {
 
@@ -118,7 +120,15 @@ export default class PageEditor extends React.Component {
   async onUpload(file) {
     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 limit');
+      toastr.error(undefined, 'MongoDB for uploading files reaches limit', {
+        closeButton: true,
+        progressBar: true,
+        newestOnTop: false,
+        showDuration: '100',
+        hideDuration: '100',
+        timeOut: '5000',
+      });
+      throw new Error('MongoDB for uploading files reaches limit');
     }
     else {
       const endpoint = '/attachments.add';

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

@@ -143,7 +143,7 @@ module.exports = function(crowi, app) {
       const usingFilesSize = await fileUploader.getCollectionSize();
       const usableCapacity = +process.env.GRIDFS_LIMIT - usingFilesSize;
       if (tmpFile.size > usableCapacity) {
-        return res.json(ApiResponse.error('mongoDB for file uploading reaches limit'));
+        return res.json(ApiResponse.error('MongoDB for uploading files reaches limit'));
       }
     }
     debug('Uploaded tmpFile: ', tmpFile);

+ 4 - 1
src/server/service/file-uploader/gridfs.js

@@ -50,7 +50,10 @@ module.exports = function(crowi) {
    */
   lib.getCollectionSize = () => {
     return new Promise((resolve, reject) => {
-      Chunks.collection.stats((e, data) => {
+      Chunks.collection.stats((err, data) => {
+        if (err) {
+          reject(err);
+        }
         resolve(data.size);
       });
     });