|
|
@@ -4,9 +4,9 @@ const util = require('util');
|
|
|
|
|
|
module.exports = function(crowi) {
|
|
|
const Uploader = require('./uploader');
|
|
|
- const lib = new Uploader(crowi.configManager);
|
|
|
+ const lib = new Uploader(crowi);
|
|
|
const COLLECTION_NAME = 'attachmentFiles';
|
|
|
- const CHUNK_COLLECTION_NAME = `${COLLECTION_NAME}.chunks`;
|
|
|
+ // const CHUNK_COLLECTION_NAME = `${COLLECTION_NAME}.chunks`;
|
|
|
|
|
|
// instantiate mongoose-gridfs
|
|
|
const { createModel } = require('mongoose-gridfs');
|
|
|
@@ -16,7 +16,7 @@ module.exports = function(crowi) {
|
|
|
connection: mongoose.connection,
|
|
|
});
|
|
|
// get Collection instance of chunk
|
|
|
- const chunkCollection = mongoose.connection.collection(CHUNK_COLLECTION_NAME);
|
|
|
+ // const chunkCollection = mongoose.connection.collection(CHUNK_COLLECTION_NAME);
|
|
|
|
|
|
// create promisified method
|
|
|
AttachmentFile.promisifiedWrite = util.promisify(AttachmentFile.write).bind(AttachmentFile);
|
|
|
@@ -46,20 +46,20 @@ module.exports = function(crowi) {
|
|
|
/**
|
|
|
* get size of data uploaded files using (Promise wrapper)
|
|
|
*/
|
|
|
- const getCollectionSize = () => {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- chunkCollection.stats((err, data) => {
|
|
|
- if (err) {
|
|
|
- // return 0 if not exist
|
|
|
- if (err.errmsg.includes('not found')) {
|
|
|
- return resolve(0);
|
|
|
- }
|
|
|
- return reject(err);
|
|
|
- }
|
|
|
- return resolve(data.size);
|
|
|
- });
|
|
|
- });
|
|
|
- };
|
|
|
+ // const getCollectionSize = () => {
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
+ // chunkCollection.stats((err, data) => {
|
|
|
+ // if (err) {
|
|
|
+ // // return 0 if not exist
|
|
|
+ // if (err.errmsg.includes('not found')) {
|
|
|
+ // return resolve(0);
|
|
|
+ // }
|
|
|
+ // return reject(err);
|
|
|
+ // }
|
|
|
+ // return resolve(data.size);
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // };
|
|
|
|
|
|
/**
|
|
|
* check the file size limit
|
|
|
@@ -70,27 +70,11 @@ module.exports = function(crowi) {
|
|
|
*/
|
|
|
lib.checkLimit = async(uploadFileSize) => {
|
|
|
const maxFileSize = crowi.configManager.getConfig('crowi', 'app:maxFileSize');
|
|
|
- if (uploadFileSize > maxFileSize) {
|
|
|
- return { isUploadable: false, errorMessage: 'File size exceeds the size limit per file' };
|
|
|
- }
|
|
|
-
|
|
|
- let usingFilesSize;
|
|
|
- try {
|
|
|
- usingFilesSize = await getCollectionSize();
|
|
|
- }
|
|
|
- catch (err) {
|
|
|
- logger.error(err);
|
|
|
- return { isUploadable: false, errorMessage: err.errmsg };
|
|
|
- }
|
|
|
|
|
|
// Use app:fileUploadTotalLimit if gridfs:totalLimit is null (default for gridfs:totalLimitd is null)
|
|
|
const gridfsTotalLimit = crowi.configManager.getConfig('crowi', 'gridfs:totalLimit')
|
|
|
|| crowi.configManager.getConfig('crowi', 'app:fileUploadTotalLimit');
|
|
|
- if (usingFilesSize + uploadFileSize > gridfsTotalLimit) {
|
|
|
- return { isUploadable: false, errorMessage: 'MongoDB for uploading files reaches limit' };
|
|
|
- }
|
|
|
-
|
|
|
- return { isUploadable: true };
|
|
|
+ return lib.doCheckLimit(uploadFileSize, maxFileSize, gridfsTotalLimit);
|
|
|
};
|
|
|
|
|
|
lib.uploadFile = async function(fileStream, attachment) {
|