itizawa 5 лет назад
Родитель
Сommit
c14f43118d
1 измененных файлов с 14 добавлено и 8 удалено
  1. 14 8
      src/server/service/file-uploader/gcs.js

+ 14 - 8
src/server/service/file-uploader/gcs.js

@@ -87,27 +87,33 @@ module.exports = function(crowi) {
 
 
   };
   };
 
 
-  lib.deleteFile = async function(attachment) {
+  lib.deleteFile = function(attachment) {
     const filePath = getFilePathOnStorage(attachment);
     const filePath = getFilePathOnStorage(attachment);
-    return lib.deleteFileByFilePath(filePath);
+    return lib.deleteFilesByFilePaths([filePath]);
   };
   };
 
 
-  lib.deleteFiles = async function(attachments) {
-    attachments.map((attachment) => {
-      return this.deleteFile(attachment);
+  lib.deleteFiles = function(attachments) {
+    const filePaths = attachments.map((attachment) => {
+      return getFilePathOnStorage(attachment);
     });
     });
+    return lib.deleteFilesByFilePaths(filePaths);
   };
   };
 
 
-  lib.deleteFileByFilePath = function(filePath) {
+  lib.deleteFilesByFilePaths = function(filePaths) {
     if (!this.getIsUploadable()) {
     if (!this.getIsUploadable()) {
       throw new Error('GCS is not configured.');
       throw new Error('GCS is not configured.');
     }
     }
 
 
     const gcs = getGcsInstance();
     const gcs = getGcsInstance();
     const myBucket = gcs.bucket(getGcsBucket());
     const myBucket = gcs.bucket(getGcsBucket());
-    const file = myBucket.file(filePath);
 
 
-    return file.delete({ ignoreNotFound: true });
+    const files = filePaths.map((filePath) => {
+      return myBucket.file(filePath);
+    });
+
+    files.forEach((file) => {
+      file.delete({ ignoreNotFound: true });
+    });
   };
   };
 
 
   lib.uploadFile = function(fileStream, attachment) {
   lib.uploadFile = function(fileStream, attachment) {