A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: reset progress on operation cancel
thecodrr5be2a5ebd6dd
diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.jsindex 1af80b72b..4d9ddafc4 100644--- a/packages/core/api/sync/index.js+++ b/packages/core/api/sync/index.js@@ -153,18 +153,23 @@ export default class Sync {async _uploadAttachments() {const attachments = this._db.attachments.pending;- console.log("Uploading attachments", this._db.attachments.pending);- for (var i = 0; i < attachments.length; ++i) {- sendAttachmentsProgressEvent("upload", attachments.length, i);+ try {+ console.log("Uploading attachments", this._db.attachments.pending);+ for (var i = 0; i < attachments.length; ++i) {+ sendAttachmentsProgressEvent("upload", attachments.length, i);- const attachment = attachments[i];- const { hash } = attachment.metadata;+ const attachment = attachments[i];+ const { hash } = attachment.metadata;- const isUploaded = await this._db.fs.uploadFile(hash, hash);- if (!isUploaded) throw new Error("Failed to upload file.");+ const isUploaded = await this._db.fs.uploadFile(hash, hash);+ if (!isUploaded) throw new Error("Failed to upload file.");- await this._db.attachments.markAsUploaded(attachment.id);+ await this._db.attachments.markAsUploaded(attachment.id);+ }+ } catch (e) {+ throw new Error("Failed to upload attachments. Error: " + e.message);+ } finally {+ sendAttachmentsProgressEvent("upload", attachments.length);}- sendAttachmentsProgressEvent("upload", attachments.length);}}diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.jsindex a20b7205c..ffcf7fb0f 100644--- a/packages/core/collections/attachments.js+++ b/packages/core/collections/attachments.js@@ -179,7 +179,9 @@ export default class Attachments extends Collection {get pending() {return this.all.filter(- (attachment) => attachment.dateUploaded <= 0 || !attachment.dateUploaded+ (attachment) =>+ (attachment.dateUploaded <= 0 || !attachment.dateUploaded) &&+ attachment.noteIds.length > 0);}diff --git a/packages/core/database/fs.js b/packages/core/database/fs.jsindex b2a50c8de..f583d2688 100644--- a/packages/core/database/fs.js+++ b/packages/core/database/fs.js@@ -28,12 +28,13 @@ export default class FileStorage {}async cancel(groupId, type = undefined) {+ console.trace("Cancelling", groupId, type);await Promise.all(this._queue.filter((item) => item.groupId === groupId && (!type || item.type === type))- .map(async (op) => await op.cancel())+ .map(async (op) => await op.cancel("Operation canceled.")));}