mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
fix: download media before note export
This commit is contained in:
@@ -68,7 +68,8 @@ class Monographs {
|
|||||||
|
|
||||||
const content = await this._db.content.downloadMedia(
|
const content = await this._db.content.downloadMedia(
|
||||||
`monograph-${noteId}`,
|
`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.");
|
if (!content) throw new Error("This note has no content.");
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
sendAttachmentsProgressEvent("download", groupId, total, current);
|
||||||
try {
|
try {
|
||||||
const isDownloaded = await this._db.fs.downloadFile(groupId, hash);
|
const isDownloaded = await this._db.fs.downloadFile(groupId, hash);
|
||||||
@@ -194,6 +194,7 @@ export default class Attachments extends Collection {
|
|||||||
const src = await this.read(hash);
|
const src = await this.read(hash);
|
||||||
if (!src) return;
|
if (!src) return;
|
||||||
|
|
||||||
|
if (notify)
|
||||||
EV.publish(EVENTS.mediaAttachmentDownloaded, {
|
EV.publish(EVENTS.mediaAttachmentDownloaded, {
|
||||||
groupId,
|
groupId,
|
||||||
hash,
|
hash,
|
||||||
|
|||||||
@@ -68,14 +68,18 @@ export default class Content extends Collection {
|
|||||||
return this._insert(contentItem, () => placeholder);
|
return this._insert(contentItem, () => placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadMedia(groupId, contentItem) {
|
async downloadMedia(groupId, contentItem, notify = true) {
|
||||||
const content = getContentFromData(contentItem.type, contentItem.data);
|
const content = getContentFromData(contentItem.type, contentItem.data);
|
||||||
contentItem.data = await content.insertMedia((hash, { total, current }) => {
|
contentItem.data = await content.insertMedia((hash, { total, current }) => {
|
||||||
return this._db.attachments._downloadMedia(hash, {
|
return this._db.attachments._downloadMedia(
|
||||||
|
hash,
|
||||||
|
{
|
||||||
total,
|
total,
|
||||||
current,
|
current,
|
||||||
groupId,
|
groupId,
|
||||||
});
|
},
|
||||||
|
notify
|
||||||
|
);
|
||||||
});
|
});
|
||||||
return contentItem;
|
return contentItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ export default class Note {
|
|||||||
* @param {string?} rawContent - Use this raw content instead of generating itself
|
* @param {string?} rawContent - Use this raw content instead of generating itself
|
||||||
*/
|
*/
|
||||||
async export(to = "html", rawContent) {
|
async export(to = "html", rawContent) {
|
||||||
|
if (to !== "txt" && !(await sendCheckUserStatusEvent(CHECK_IDS.noteExport)))
|
||||||
|
return false;
|
||||||
|
|
||||||
const templateData = {
|
const templateData = {
|
||||||
metadata: this.data,
|
metadata: this.data,
|
||||||
title: this.title,
|
title: this.title,
|
||||||
@@ -65,12 +68,15 @@ export default class Note {
|
|||||||
headline: this.headline,
|
headline: this.headline,
|
||||||
createdOn: this.data.dateCreated,
|
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);
|
let content = getContentFromData(type, data);
|
||||||
|
|
||||||
if (to !== "txt" && !(await sendCheckUserStatusEvent(CHECK_IDS.noteExport)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (to) {
|
switch (to) {
|
||||||
case "html":
|
case "html":
|
||||||
templateData.content = rawContent || content.toHTML();
|
templateData.content = rawContent || content.toHTML();
|
||||||
@@ -86,11 +92,8 @@ export default class Note {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async content(withAttachments = false) {
|
async content() {
|
||||||
const content = await this._db.content.raw(
|
const content = await this._db.content.raw(this._note.contentId);
|
||||||
this._note.contentId,
|
|
||||||
withAttachments
|
|
||||||
);
|
|
||||||
return content.data;
|
return content.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user