diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.js index 5370d9994..48bfe100b 100644 --- a/packages/core/collections/attachments.js +++ b/packages/core/collections/attachments.js @@ -177,7 +177,7 @@ export default class Attachments extends Collection { * Get specified type of attachments of a note * @param {string} noteId * @param {"files"|"images"|"all"} type - * @returns + * @returns {Array} */ ofNote(noteId, type) { let attachments = []; diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js index e2fb8ce18..6f0996c69 100644 --- a/packages/core/collections/notes.js +++ b/packages/core/collections/notes.js @@ -202,6 +202,15 @@ export default class Notes extends Collection { if (itemData.color) { await this._db.colors.untag(itemData.color, id); } + + const attachments = this._db.attachments.ofNote(itemData.id, "all"); + for (let attachment of attachments) { + await this._db.attachments.delete( + attachment.metadata.hash, + itemData.id + ); + } + // await this._collection.removeItem(id); if (moveToTrash) await this._db.trash.add(itemData); else {