zamis 5 лет назад
Родитель
Сommit
9516c6304b
1 измененных файлов с 17 добавлено и 0 удалено
  1. 17 0
      src/server/service/file-uploader/gridfs.js

+ 17 - 0
src/server/service/file-uploader/gridfs.js

@@ -26,6 +26,23 @@ module.exports = function(crowi) {
     return true;
   };
 
+  lib.deleteFile = async function(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 });
+  };
+
   lib.deleteFiles = async function(attachments) {
 
     attachments.map(async(attachment) => {