Răsfoiți Sursa

use deleteObjects

zamis 5 ani în urmă
părinte
comite
8d4e169d00
1 a modificat fișierele cu 27 adăugiri și 2 ștergeri
  1. 27 2
      src/server/service/file-uploader/aws.js

+ 27 - 2
src/server/service/file-uploader/aws.js

@@ -116,9 +116,34 @@ module.exports = function(crowi) {
   };
 
   lib.deleteFiles = async function(attachments) {
-    attachments.map((attachment) => {
-      return this.deleteFile(attachment);
+    const s3 = S3Factory();
+    const awsConfig = getAwsConfig();
+
+    const filePaths = [];
+    attachments.forEach(attachment => filePaths.push(getFilePathOnStorage(attachment)));
+
+    const totalParams = {
+      Bucket: awsConfig.bucket,
+      Delete: { Objects: [] },
+    };
+
+    const Objects = [];
+    filePaths.forEach((filePath) => {
+      Objects.push({ Key: filePath });
+    });
+
+    Objects.forEach((object) => {
+      totalParams.Delete.Objects.push(object);
     });
+    console.log(Objects);
+
+    console.log(totalParams);
+
+    return s3.deleteObjects(totalParams).promise();
+
+    // attachments.map((attachment) => {
+    //   return this.deleteFile(attachment);
+    // });
   };
 
   lib.deleteFileByFilePath = async function(filePath) {