From 30bcd1764a66cf074b7b7e3092c5db46fe00ab32 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 14 Jul 2023 21:28:32 +0200 Subject: [PATCH] check the attachment after upload --- src/becca/entities/bnote.js | 2 +- src/services/image.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index 4225908a9..b009cef29 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -1496,7 +1496,7 @@ class BNote extends AbstractBeccaEntity { parentNote.setContent(fixedContent); const noteService = require("../../services/notes"); - noteService.asyncPostProcessContent(parentNote, fixedContent); + noteService.asyncPostProcessContent(parentNote, fixedContent); // to mark an unused attachment for deletion this.deleteNote(); diff --git a/src/services/image.js b/src/services/image.js index a6b08a4d5..de71493f3 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -142,15 +142,21 @@ function saveImageToAttachment(noteId, uploadBuffer, originalName, shrinkImageSw const fileName = sanitizeFilename(originalName); const note = becca.getNoteOrThrow(noteId); - const attachment = note.saveAttachment({ + let attachment = note.saveAttachment({ role: 'image', mime: 'unknown', title: fileName }); + const noteService = require("../services/notes"); + noteService.asyncPostProcessContent(note, note.getContent()); // to mark an unused attachment for deletion + // resizing images asynchronously since JIMP does not support sync operation processImage(uploadBuffer, originalName, shrinkImageSwitch).then(({buffer, imageFormat}) => { sql.transactional(() => { + // re-read, might be changed in the meantime + attachment = becca.getAttachmentOrThrow(attachment.attachmentId); + attachment.mime = getImageMimeFromExtension(imageFormat.ext); if (!originalName.includes(".")) {