mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix: reset progress on operation cancel
This commit is contained in:
@@ -153,18 +153,23 @@ export default class Sync {
|
|||||||
|
|
||||||
async _uploadAttachments() {
|
async _uploadAttachments() {
|
||||||
const attachments = this._db.attachments.pending;
|
const attachments = this._db.attachments.pending;
|
||||||
console.log("Uploading attachments", this._db.attachments.pending);
|
try {
|
||||||
for (var i = 0; i < attachments.length; ++i) {
|
console.log("Uploading attachments", this._db.attachments.pending);
|
||||||
sendAttachmentsProgressEvent("upload", attachments.length, i);
|
for (var i = 0; i < attachments.length; ++i) {
|
||||||
|
sendAttachmentsProgressEvent("upload", attachments.length, i);
|
||||||
|
|
||||||
const attachment = attachments[i];
|
const attachment = attachments[i];
|
||||||
const { hash } = attachment.metadata;
|
const { hash } = attachment.metadata;
|
||||||
|
|
||||||
const isUploaded = await this._db.fs.uploadFile(hash, hash);
|
const isUploaded = await this._db.fs.uploadFile(hash, hash);
|
||||||
if (!isUploaded) throw new Error("Failed to upload file.");
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,9 @@ export default class Attachments extends Collection {
|
|||||||
|
|
||||||
get pending() {
|
get pending() {
|
||||||
return this.all.filter(
|
return this.all.filter(
|
||||||
(attachment) => attachment.dateUploaded <= 0 || !attachment.dateUploaded
|
(attachment) =>
|
||||||
|
(attachment.dateUploaded <= 0 || !attachment.dateUploaded) &&
|
||||||
|
attachment.noteIds.length > 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,13 @@ export default class FileStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async cancel(groupId, type = undefined) {
|
async cancel(groupId, type = undefined) {
|
||||||
|
console.trace("Cancelling", groupId, type);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
this._queue
|
this._queue
|
||||||
.filter(
|
.filter(
|
||||||
(item) => item.groupId === groupId && (!type || item.type === type)
|
(item) => item.groupId === groupId && (!type || item.type === type)
|
||||||
)
|
)
|
||||||
.map(async (op) => await op.cancel())
|
.map(async (op) => await op.cancel("Operation canceled."))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user