fix: reset progress on operation cancel

This commit is contained in:
thecodrr
2021-10-01 11:40:18 +05:00
parent 71f7e25a17
commit 5be2a5ebd6
3 changed files with 19 additions and 11 deletions

View File

@@ -153,6 +153,7 @@ export default class Sync {
async _uploadAttachments() {
const attachments = this._db.attachments.pending;
try {
console.log("Uploading attachments", this._db.attachments.pending);
for (var i = 0; i < attachments.length; ++i) {
sendAttachmentsProgressEvent("upload", attachments.length, i);
@@ -165,6 +166,10 @@ export default class Sync {
await this._db.attachments.markAsUploaded(attachment.id);
}
} catch (e) {
throw new Error("Failed to upload attachments. Error: " + e.message);
} finally {
sendAttachmentsProgressEvent("upload", attachments.length);
}
}
}

View File

@@ -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
);
}

View File

@@ -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."))
);
}