Просмотр исходного кода

Make necessary upload configs persistent

Taichi Masuyama 3 лет назад
Родитель
Сommit
5800725ff3

+ 1 - 1
packages/app/src/server/routes/apiv3/g2g-transfer.ts

@@ -338,7 +338,7 @@ module.exports = (crowi: Crowi): Router => {
 
 
     // Start transfer
     // Start transfer
     try {
     try {
-      await g2gTransferPusherService.startTransfer(tk, req.user, collections, optionsMap);
+      await g2gTransferPusherService.startTransfer(tk, req.user, toGROWIInfo, collections, optionsMap);
     }
     }
     catch (err) {
     catch (err) {
       logger.error(err);
       logger.error(err);

+ 34 - 3
packages/app/src/server/service/g2g-transfer.ts

@@ -24,7 +24,12 @@ export const X_GROWI_TRANSFER_KEY_HEADER_NAME = 'x-growi-transfer-key';
 export type IDataGROWIInfo = {
 export type IDataGROWIInfo = {
   version: string
   version: string
   userUpperLimit: number | null // Handle null as Infinity
   userUpperLimit: number | null // Handle null as Infinity
-  attachmentInfo: any
+  attachmentInfo: {
+    type: string,
+    bucket?: string,
+    customEndpoint?: string, // for S3
+    uploadNamespace?: string, // for GCS
+  };
 }
 }
 
 
 interface Pusher {
 interface Pusher {
@@ -49,7 +54,7 @@ interface Pusher {
    * @param {string[]} collections Collection name string array
    * @param {string[]} collections Collection name string array
    * @param {any} optionsMap Options map
    * @param {any} optionsMap Options map
    */
    */
-  startTransfer(tk: TransferKey, user: any, collections: string[], optionsMap: any): Promise<void>
+  startTransfer(tk: TransferKey, user: any, toGROWIInfo: IDataGROWIInfo, collections: string[], optionsMap: any): Promise<void>
 }
 }
 
 
 interface Receiver {
 interface Receiver {
@@ -213,7 +218,7 @@ export class G2GTransferPusherService implements Pusher {
     }
     }
   }
   }
 
 
-  public async startTransfer(tk: TransferKey, user: any, collections: string[], optionsMap: any): Promise<void> {
+  public async startTransfer(tk: TransferKey, user: any, toGROWIInfo: IDataGROWIInfo, collections: string[], optionsMap: any): Promise<void> {
     let zipFileStream: ReadStream;
     let zipFileStream: ReadStream;
     try {
     try {
       const shouldEmit = false;
       const shouldEmit = false;
@@ -227,6 +232,32 @@ export class G2GTransferPusherService implements Pusher {
       throw err;
       throw err;
     }
     }
 
 
+    if (toGROWIInfo.attachmentInfo.type === 'none') {
+      try {
+        const targetConfigKeys = [
+          'app:fileUploadType',
+          'app:useOnlyEnvVarForFileUploadType',
+          'aws:referenceFileWithRelayMode',
+          'aws:lifetimeSecForTemporaryUrl',
+          'gcs:apiKeyJsonPath',
+          'gcs:bucket',
+          'gcs:uploadNamespace',
+          'gcs:referenceFileWithRelayMode',
+          'gcs:useOnlyEnvVarsForSomeOptions',
+        ];
+
+        const updateConfigs = Object.fromEntries(targetConfigKeys.map((key) => {
+          return [key, this.crowi.configManager.getConfig('crowi', key)];
+        }));
+
+        await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', updateConfigs);
+      }
+      catch (err) {
+        logger.error(err);
+        throw err;
+      }
+    }
+
     // Send a zip file to other growi via axios
     // Send a zip file to other growi via axios
     try {
     try {
       // Use FormData to immitate browser's form data object
       // Use FormData to immitate browser's form data object