|
|
@@ -1,4 +1,5 @@
|
|
|
const logger = require('@alias/logger')('growi:service:FileUploaderServise');
|
|
|
+const Gridfs = require('./gridfs');
|
|
|
|
|
|
const envToModuleMappings = {
|
|
|
aws: 'aws',
|
|
|
@@ -19,7 +20,7 @@ class FileUploaderServise {
|
|
|
this.appService = crowi.appService;
|
|
|
this.configManager = crowi.configManager;
|
|
|
|
|
|
- this.fileUploader = {};
|
|
|
+ this.fileUploader = null;
|
|
|
|
|
|
/**
|
|
|
* the flag whether fileUploader is set up successfully
|
|
|
@@ -29,19 +30,26 @@ class FileUploaderServise {
|
|
|
this.initialize();
|
|
|
}
|
|
|
|
|
|
- initialize() {
|
|
|
- logger.info('setUP!');
|
|
|
- this.fileUploader = this.getUploader(this.crowi);
|
|
|
- }
|
|
|
+ async initialize() {
|
|
|
+ this.isFileUploaderSetup = false;
|
|
|
+
|
|
|
+ const method = envToModuleMappings[process.env.FILE_UPLOAD] || 'aws';
|
|
|
+
|
|
|
+ switch (method) {
|
|
|
+ case 'gridfs':
|
|
|
+ this.fileUploader = new Gridfs(this.crowi);
|
|
|
+ break;
|
|
|
+ // TODO others
|
|
|
+ default:
|
|
|
+ this.fileUploader = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- getUploader(crowi) {
|
|
|
- if (this.fileUploader == null) {
|
|
|
- const method = envToModuleMappings[process.env.FILE_UPLOAD] || 'aws';
|
|
|
- const modulePath = `./${method}`;
|
|
|
- this.uploader = require(modulePath)(crowi);
|
|
|
+ if (this.fileUploader != null) {
|
|
|
+ this.isFileUploaderSetup = true;
|
|
|
}
|
|
|
|
|
|
- return this.fileUploader;
|
|
|
+ logger.debug('fileUploader initialized');
|
|
|
}
|
|
|
|
|
|
}
|