mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
core: add download start & canceled events
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user