diff --git a/packages/core/api/monographs.js b/packages/core/api/monographs.js index da701c0d9..5d1217f71 100644 --- a/packages/core/api/monographs.js +++ b/packages/core/api/monographs.js @@ -68,7 +68,8 @@ class Monographs { const content = await this._db.content.downloadMedia( `monograph-${noteId}`, - await this._db.content.raw(note.data.contentId) + await this._db.content.raw(note.data.contentId), + false ); if (!content) throw new Error("This note has no content."); diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.js index c96c7214d..75e8b9856 100644 --- a/packages/core/collections/attachments.js +++ b/packages/core/collections/attachments.js @@ -185,7 +185,7 @@ export default class Attachments extends Collection { } } - async _downloadMedia(hash, { total, current, groupId }) { + async _downloadMedia(hash, { total, current, groupId }, notify = true) { sendAttachmentsProgressEvent("download", groupId, total, current); try { const isDownloaded = await this._db.fs.downloadFile(groupId, hash); @@ -194,11 +194,12 @@ export default class Attachments extends Collection { const src = await this.read(hash); if (!src) return; - EV.publish(EVENTS.mediaAttachmentDownloaded, { - groupId, - hash, - src, - }); + if (notify) + EV.publish(EVENTS.mediaAttachmentDownloaded, { + groupId, + hash, + src, + }); return src; } finally { diff --git a/packages/core/collections/content.js b/packages/core/collections/content.js index 19011dce7..490d8f760 100644 --- a/packages/core/collections/content.js +++ b/packages/core/collections/content.js @@ -68,14 +68,18 @@ export default class Content extends Collection { return this._insert(contentItem, () => placeholder); } - async downloadMedia(groupId, contentItem) { + async downloadMedia(groupId, contentItem, notify = true) { const content = getContentFromData(contentItem.type, contentItem.data); contentItem.data = await content.insertMedia((hash, { total, current }) => { - return this._db.attachments._downloadMedia(hash, { - total, - current, - groupId, - }); + return this._db.attachments._downloadMedia( + hash, + { + total, + current, + groupId, + }, + notify + ); }); return contentItem; } diff --git a/packages/core/models/note.js b/packages/core/models/note.js index 4316150c1..84d449e57 100644 --- a/packages/core/models/note.js +++ b/packages/core/models/note.js @@ -58,6 +58,9 @@ export default class Note { * @param {string?} rawContent - Use this raw content instead of generating itself */ async export(to = "html", rawContent) { + if (to !== "txt" && !(await sendCheckUserStatusEvent(CHECK_IDS.noteExport))) + return false; + const templateData = { metadata: this.data, title: this.title, @@ -65,12 +68,15 @@ export default class Note { headline: this.headline, createdOn: this.data.dateCreated, }; - const { data, type } = await this._db.content.raw(this._note.contentId); + const contentItem = await this._db.content.raw(this._note.contentId); + if (!contentItem) return false; + const { data, type } = await this._db.content.downloadMedia( + `export-${this.id}`, + contentItem, + false + ); let content = getContentFromData(type, data); - if (to !== "txt" && !(await sendCheckUserStatusEvent(CHECK_IDS.noteExport))) - return; - switch (to) { case "html": templateData.content = rawContent || content.toHTML(); @@ -86,11 +92,8 @@ export default class Note { } } - async content(withAttachments = false) { - const content = await this._db.content.raw( - this._note.contentId, - withAttachments - ); + async content() { + const content = await this._db.content.raw(this._note.contentId); return content.data; }