Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: add download start & canceled events

ammarahm-ed883fe4894612
diff --git a/packages/core/src/common.js b/packages/core/src/common.js
index ca6d2e661..5202aad70 100644
--- a/packages/core/src/common.js
+++ b/packages/core/src/common.js
@@ -89,6 +89,10 @@ export const EVENTS = {
noteRemoved: "note:removed",
tokenRefreshed: "token:refreshed",
userUnauthorized: "user:unauthorized",
+ downloadCanceled: "file:downloadCanceled",
+ uploadCanceled: "file:uploadCanceled",
+ fileDownload: "file:download",
+ fileUpload: "file:upload",
fileDownloaded: "file:downloaded",
fileUploaded: "file:uploaded",
attachmentDeleted: "attachment:deleted",
diff --git a/packages/core/src/database/fs.js b/packages/core/src/database/fs.js
index 21a3f0e27..b8ec7afe4 100644
--- a/packages/core/src/database/fs.js
+++ b/packages/core/src/database/fs.js
@@ -45,8 +45,14 @@ export default class FileStorage {
});
file.cancel = cancel;
- const result = await execute().catch(() => false);
+ EV.publish(EVENTS.fileDownload, {
+ total,
+ current,
+ groupId,
+ filename
+ });
+ const result = await execute().catch(() => false);
if (eventData)
EV.publish(EVENTS.fileDownloaded, {
success: result,
@@ -75,6 +81,13 @@ export default class FileStorage {
});
file.cancel = cancel;
+ EV.publish(EVENTS.fileUpload, {
+ total,
+ current,
+ groupId,
+ filename
+ });
+
let error = null;
const result = await execute().catch((e) => {
console.error("Failed to upload attachment:", e);
@@ -111,7 +124,7 @@ export default class FileStorage {
async cancel(groupId, type) {
const queue =
- type === "downloads"
+ type === "download"
? this.downloads.get(groupId)
: this.uploads.get(groupId);
if (!queue) return;
@@ -120,8 +133,13 @@ export default class FileStorage {
if (file.cancel) await file.cancel("Operation canceled.");
queue.splice(i, 1);
}
- if (type === "download") this.downloads.delete(groupId);
- else if (type === "upload") this.uploads.delete(groupId);
+ if (type === "download") {
+ this.downloads.delete(groupId);
+ EV.publish(EVENTS.downloadCanceled, { groupId, canceled: true });
+ } else if (type === "upload") {
+ this.uploads.delete(groupId);
+ EV.publish(EVENTS.uploadCanceled, { groupId, canceled: true });
+ }
}
readEncrypted(filename, encryptionKey, cipherData) {