ソースを参照

move create timing of fileUploadeService instance

yusuketk 5 年 前
コミット
f507b746d9

+ 3 - 1
src/server/crowi/index.js

@@ -548,7 +548,9 @@ Crowi.prototype.setUpApp = async function() {
  */
  */
 Crowi.prototype.setUpFileUpload = async function() {
 Crowi.prototype.setUpFileUpload = async function() {
   if (this.fileUploadService == null) {
   if (this.fileUploadService == null) {
-    this.fileUploadService = require('../service/file-uploader')(this);
+    const FileUploadServiceFactory = require('../service/file-uploader');
+    this.fileUploadServiceFactory = new FileUploadServiceFactory(this);
+    this.fileUploadService = this.fileUploadServiceFactory.getUploader(this);
 
 
     // add as a message handler
     // add as a message handler
     if (this.s2sMessagingService != null) {
     if (this.s2sMessagingService != null) {

+ 4 - 0
src/server/routes/apiv3/app-settings.js

@@ -581,6 +581,8 @@ module.exports = (crowi) => {
 
 
     try {
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestAwsSettingParams, true);
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestAwsSettingParams, true);
+      crowi.fileUploadServiceFactory.initializeUploader(crowi);
+      crowi.fileUploadService = crowi.fileUploadServiceFactory.getUploader(crowi);
       crowi.fileUploadService.publishUpdatedMessage();
       crowi.fileUploadService.publishUpdatedMessage();
 
 
       const awsSettingParams = {
       const awsSettingParams = {
@@ -633,6 +635,8 @@ module.exports = (crowi) => {
 
 
     try {
     try {
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestGcpSettingParams, true);
       await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestGcpSettingParams, true);
+      crowi.fileUploadServiceFactory.initializeUploader(crowi);
+      crowi.fileUploadService = crowi.fileUploadServiceFactory.getUploader(crowi);
       crowi.fileUploadService.publishUpdatedMessage();
       crowi.fileUploadService.publishUpdatedMessage();
 
 
       const gcpSettingParams = {
       const gcpSettingParams = {

+ 3 - 7
src/server/service/file-uploader/index.js

@@ -14,8 +14,8 @@ const envToModuleMappings = {
 class FileUploadServiceFactory {
 class FileUploadServiceFactory {
 
 
   initializeUploader(crowi) {
   initializeUploader(crowi) {
-    const method = envToModuleMappings[process.env.FILE_UPLOAD] || 'aws';
-
+    const fileUplodeTypeInConfig = envToModuleMappings[crowi.configManager.getConfig('crowi', 'app:fileUploadType')];
+    const method = envToModuleMappings[process.env.FILE_UPLOAD] || fileUplodeTypeInConfig || 'ppp';
     const modulePath = `./${method}`;
     const modulePath = `./${method}`;
     this.uploader = require(modulePath)(crowi);
     this.uploader = require(modulePath)(crowi);
 
 
@@ -33,8 +33,4 @@ class FileUploadServiceFactory {
 
 
 }
 }
 
 
-
-module.exports = (crowi) => {
-  const factory = new FileUploadServiceFactory(crowi);
-  return factory.getUploader(crowi);
-};
+module.exports = FileUploadServiceFactory;