zamis před 5 roky
rodič
revize
bec415236d

+ 1 - 1
src/server/service/attachment.js

@@ -48,7 +48,7 @@ class AttachmentService {
     const attachmentsCollection = mongoose.connection.collection('attachments');
     const unorderAttachmentsBulkOp = attachmentsCollection.initializeUnorderedBulkOp();
 
-    if (attachments.length > 1) {
+    if (attachments.length > 0) {
       fileUploadService.deleteFiles(attachments);
 
       attachments.forEach((attachment) => {

+ 1 - 1
src/server/service/file-uploader/aws.js

@@ -117,7 +117,7 @@ module.exports = function(crowi) {
 
   lib.deleteFiles = async function(attachments) {
     attachments.map((attachment) => {
-      return lib.deleteFile(attachment);
+      return this.deleteFile(attachment);
     });
   };
 

+ 6 - 2
src/server/service/file-uploader/gcs.js

@@ -87,10 +87,14 @@ module.exports = function(crowi) {
 
   };
 
+  lib.deleteFile = async function(attachment) {
+    const filePath = getFilePathOnStorage(attachment);
+    return lib.deleteFileByFilePath(filePath);
+  };
+
   lib.deleteFiles = async function(attachments) {
     attachments.map((attachment) => {
-      const filePath = getFilePathOnStorage(attachment);
-      return lib.deleteFileByFilePath(filePath);
+      return this.deleteFile(attachment);
     });
   };
 

+ 1 - 16
src/server/service/file-uploader/gridfs.js

@@ -44,24 +44,9 @@ module.exports = function(crowi) {
   };
 
   lib.deleteFiles = async function(attachments) {
-
     attachments.map(async(attachment) => {
-      let filenameValue = attachment.fileName;
-
-      if (attachment.filePath != null) { // backward compatibility for v3.3.x or below
-        filenameValue = attachment.filePath;
-      }
-
-      const attachmentFile = await AttachmentFile.findOne({ filename: filenameValue });
-
-      if (attachmentFile == null) {
-        logger.warn(`Any AttachmentFile that relate to the Attachment (${attachment._id.toString()}) does not exist in GridFS`);
-        return;
-      }
-      return AttachmentFile.promisifiedUnlink({ _id: attachmentFile._id });
+      return lib.deleteFile(attachment);
     });
-
-
   };
 
   /**

+ 6 - 2
src/server/service/file-uploader/local.js

@@ -30,10 +30,14 @@ module.exports = function(crowi) {
     return true;
   };
 
+  lib.deleteFile = async function(attachment) {
+    const filePath = getFilePathOnStorage(attachment);
+    return lib.deleteFileByFilePath(filePath);
+  };
+
   lib.deleteFiles = async function(attachments) {
     attachments.map((attachment) => {
-      const filePath = getFilePathOnStorage(attachment);
-      return lib.deleteFileByFilePath(filePath);
+      return this.deleteFile(attachment);
     });
   };