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

feat: stop g2g transfer when storage is writable

mizozobu 3 лет назад
Родитель
Сommit
db67297518

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

@@ -335,8 +335,6 @@ module.exports = (crowi: Crowi): Router => {
     return res.apiv3({ transferKey: transferKeyString });
     return res.apiv3({ transferKey: transferKeyString });
   });
   });
 
 
-  // Auto export
-  // TODO: Use socket to send progress info to the client
   // eslint-disable-next-line max-len
   // eslint-disable-next-line max-len
   pushRouter.post('/transfer', accessTokenParser, loginRequiredStrictly, adminRequired, validator.transfer, apiV3FormValidator, async(req: AuthorizedRequest, res: ApiV3Response) => {
   pushRouter.post('/transfer', accessTokenParser, loginRequiredStrictly, adminRequired, validator.transfer, apiV3FormValidator, async(req: AuthorizedRequest, res: ApiV3Response) => {
     const { transferKey, collections, optionsMap } = req.body;
     const { transferKey, collections, optionsMap } = req.body;
@@ -351,8 +349,7 @@ module.exports = (crowi: Crowi): Router => {
       return res.apiv3Err(new ErrorV3('Transfer key is invalid', 'transfer_key_invalid'), 400);
       return res.apiv3Err(new ErrorV3('Transfer key is invalid', 'transfer_key_invalid'), 400);
     }
     }
 
 
-    // Ask growi info
-    // TODO: Ask progress as well
+    // get growi info
     let toGROWIInfo: IDataGROWIInfo;
     let toGROWIInfo: IDataGROWIInfo;
     try {
     try {
       toGROWIInfo = await g2gTransferPusherService.askGROWIInfo(tk);
       toGROWIInfo = await g2gTransferPusherService.askGROWIInfo(tk);

+ 16 - 11
packages/app/src/server/service/g2g-transfer.ts

@@ -41,10 +41,11 @@ export type IDataGROWIInfo = {
   fileUploadDisabled: boolean;
   fileUploadDisabled: boolean;
   fileUploadTotalLimit: number | null // Handle null as Infinity
   fileUploadTotalLimit: number | null // Handle null as Infinity
   attachmentInfo: {
   attachmentInfo: {
-    type: string,
-    bucket?: string,
-    customEndpoint?: string, // for S3
-    uploadNamespace?: string, // for GCS
+    type: string;
+    writable: boolean;
+    bucket?: string;
+    customEndpoint?: string; // for S3
+    uploadNamespace?: string; // for GCS
   };
   };
 }
 }
 
 
@@ -149,18 +150,14 @@ export class G2GTransferPusherService implements Pusher {
   }
   }
 
 
   public async askGROWIInfo(tk: TransferKey): Promise<IDataGROWIInfo> {
   public async askGROWIInfo(tk: TransferKey): Promise<IDataGROWIInfo> {
-    // axios get
-    let toGROWIInfo: IDataGROWIInfo;
     try {
     try {
-      const res = await axios.get('/_api/v3/g2g-transfer/growi-info', generateAxiosRequestConfigWithTransferKey(tk));
-      toGROWIInfo = res.data.growiInfo;
+      const { data: { growiInfo } } = await axios.get('/_api/v3/g2g-transfer/growi-info', generateAxiosRequestConfigWithTransferKey(tk));
+      return growiInfo;
     }
     }
     catch (err) {
     catch (err) {
       logger.error(err);
       logger.error(err);
       throw new G2GTransferError('Failed to retrieve growi info.', G2GTransferErrorCode.FAILED_TO_RETRIEVE_GROWI_INFO);
       throw new G2GTransferError('Failed to retrieve growi info.', G2GTransferErrorCode.FAILED_TO_RETRIEVE_GROWI_INFO);
     }
     }
-
-    return toGROWIInfo;
   }
   }
 
 
   /**
   /**
@@ -197,6 +194,14 @@ export class G2GTransferPusherService implements Pusher {
       };
       };
     }
     }
 
 
+    if (!toGROWIInfo.attachmentInfo.writable) {
+      return {
+        canTransfer: false,
+        // TODO: i18n for reason
+        reason: 'The storage of new Growi is not writable.',
+      };
+    }
+
     const totalFileSize = await fileUploadService.getTotalFileSize();
     const totalFileSize = await fileUploadService.getTotalFileSize();
     if ((toGROWIInfo.fileUploadTotalLimit ?? Infinity) < totalFileSize) {
     if ((toGROWIInfo.fileUploadTotalLimit ?? Infinity) < totalFileSize) {
       return {
       return {
@@ -445,10 +450,10 @@ export class G2GTransferReceiverService implements Receiver {
 
 
     const attachmentInfo = {
     const attachmentInfo = {
       type: configManager.getConfig('crowi', 'app:fileUploadType'),
       type: configManager.getConfig('crowi', 'app:fileUploadType'),
+      writable: isWritable,
       bucket: undefined,
       bucket: undefined,
       customEndpoint: undefined, // for S3
       customEndpoint: undefined, // for S3
       uploadNamespace: undefined, // for GCS
       uploadNamespace: undefined, // for GCS
-      writable: isWritable,
     };
     };
 
 
     // put storage location info to check storage identification
     // put storage location info to check storage identification