|
|
@@ -101,7 +101,23 @@ module.exports = function(crowi) {
|
|
|
*/
|
|
|
lib.checkLimit = async(uploadFileSize) => {
|
|
|
const maxFileSize = crowi.configManager.getConfig('crowi', 'app:maxFileSize');
|
|
|
- return { isUploadable: uploadFileSize <= maxFileSize, errorMessage: 'File size exceeds the size limit per file' };
|
|
|
+ if (uploadFileSize > maxFileSize) {
|
|
|
+ return { isUploadable: false, errorMessage: 'File size exceeds the size limit per file' };
|
|
|
+ }
|
|
|
+ const Attachment = crowi.model('Attachment');
|
|
|
+ // Get attachment total file size
|
|
|
+ const res = await Attachment.aggregate().group({
|
|
|
+ _id: null,
|
|
|
+ total: { $sum: '$fileSize' },
|
|
|
+ });
|
|
|
+ const usingFilesSize = res[0].total;
|
|
|
+
|
|
|
+ const gcsTotalLimit = crowi.configManager.getConfig('crowi', 'app:fileUploadTotalLimit');
|
|
|
+ if (usingFilesSize + uploadFileSize > gcsTotalLimit) {
|
|
|
+ return { isUploadable: false, errorMessage: 'GCS for uploading files reaches limit' };
|
|
|
+ }
|
|
|
+
|
|
|
+ return { isUploadable: true };
|
|
|
};
|
|
|
|
|
|
return lib;
|