itizawa 5 lat temu
rodzic
commit
7700959363

+ 18 - 1
src/client/js/services/AdminAppContainer.js

@@ -364,7 +364,11 @@ export default class AdminAppContainer extends Container {
     if (this.state.fileUploadType === 'aws') {
       return this.updateAwsSettingHandler();
     }
-    return this.updateGcpSettingHandler();
+    if (this.state.fileUploadType === 'gcp') {
+      return this.updateGcpSettingHandler();
+    }
+    // only update fileUploadType
+    return this.updateFileUploadTypeHandler();
   }
 
   /**
@@ -401,6 +405,19 @@ export default class AdminAppContainer extends Container {
     return awsSettingParams;
   }
 
+  /**
+   * Update file upload type
+   * @memberOf AdminAppContainer
+   * @return {Array} Appearance
+   */
+  async updateFileUploadTypeHandler() {
+    const response = await this.appContainer.apiv3.put('/app-settings/file-upload-type', {
+      fileUploadType: this.state.fileUploadType,
+    });
+    const { awsSettingParams } = response.data;
+    return awsSettingParams;
+  }
+
   /**
    * Update plugin setting
    * @memberOf AdminAppContainer

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

@@ -127,6 +127,13 @@ const ErrorV3 = require('../../models/vo/error-apiv3');
  *          envGcsUploadNamespace:
  *            type: string
  *            description: Directory name to create in the bucket
+ *      FileUploadTypeParams:
+ *        description: FileUploadTypeParams
+ *        type: object
+ *        properties:
+ *          fileUploadType:
+ *            type: string
+ *            description: fileUploadType
  *      PluginSettingParams:
  *        description: PluginSettingParams
  *        type: object
@@ -180,6 +187,9 @@ module.exports = (crowi) => {
       body('gcsBucket').trim(),
       body('gcsUploadNamespace').trim(),
     ],
+    fileUploadType: [
+      body('fileUploadType').isIn(['aws', 'gcp', 'local', 'gridfs']),
+    ],
     pluginSetting: [
       body('isEnabledPlugins').isBoolean(),
     ],
@@ -652,6 +662,52 @@ module.exports = (crowi) => {
 
   });
 
+  /**
+   * @swagger
+   *
+   *    /app-settings/file-upload-type:
+   *      put:
+   *        tags: [AppSettings]
+   *        operationId: updateAppSettingGcpSetting
+   *        summary: /app-settings/file-upload-type
+   *        description: Update fileUploadType
+   *        requestBody:
+   *          required: true
+   *          content:
+   *            application/json:
+   *              schema:
+   *                $ref: '#/components/schemas/GcpSettingParams'
+   *        responses:
+   *          200:
+   *            description: Succeeded to update fileUploadType
+   *            content:
+   *              application/json:
+   *                schema:
+   *                  $ref: '#/components/schemas/GcpSettingParams'
+   */
+  router.put('/file-upload-type', loginRequiredStrictly, adminRequired, csrf, validator.fileUploadType, apiV3FormValidator, async(req, res) => {
+    const requestParams = {
+      'app:fileUploadType': req.body.fileUploadType,
+    };
+
+    try {
+      await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams, true);
+      await crowi.setUpFileUpload(true);
+      crowi.fileUploaderSwitchService.publishUpdatedMessage();
+
+      const responseParams = {
+        fileUploadType: crowi.configManager.getConfig('crowi', 'gcs:fileUploadType'),
+      };
+      return res.apiv3({ responseParams });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating fileUploadType';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-fileUploadType-failed'));
+    }
+
+  });
+
   /**
    * @swagger
    *