mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
web: show progress when rechecking attachments in bulk
This commit is contained in:
@@ -28,6 +28,7 @@ import { AttachmentStream } from "../utils/streams/attachment-stream";
|
||||
import { createZipStream } from "../utils/streams/zip-stream";
|
||||
import { createWriteStream } from "../utils/stream-saver";
|
||||
import { Attachment } from "@notesnook/core";
|
||||
import { TaskManager } from "../common/task-manager";
|
||||
|
||||
let abortController: AbortController | undefined = undefined;
|
||||
class AttachmentStore extends BaseStore<AttachmentStore> {
|
||||
@@ -80,25 +81,36 @@ class AttachmentStore extends BaseStore<AttachmentStore> {
|
||||
};
|
||||
|
||||
recheck = async (ids: string[]) => {
|
||||
for (const id of ids) {
|
||||
const attachment = await db.attachments.attachment(id);
|
||||
if (!attachment) continue;
|
||||
try {
|
||||
this._changeWorkingStatus(attachment.hash, "recheck");
|
||||
await TaskManager.startTask({
|
||||
type: "status",
|
||||
action: async (report) => {
|
||||
let i = 0;
|
||||
for (const id of ids) {
|
||||
report({
|
||||
text: `Checking attachments (${++i}/${ids.length})`
|
||||
});
|
||||
const attachment = await db.attachments.attachment(id);
|
||||
if (!attachment) continue;
|
||||
try {
|
||||
this._changeWorkingStatus(attachment.hash, "recheck");
|
||||
|
||||
const { failed, success } = await checkAttachment(attachment.hash);
|
||||
this._changeWorkingStatus(
|
||||
attachment.hash,
|
||||
undefined,
|
||||
success ? undefined : failed
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this._changeWorkingStatus(attachment.hash);
|
||||
if (e instanceof Error)
|
||||
showToast("error", `Rechecking failed: ${e.message}`);
|
||||
}
|
||||
}
|
||||
const { failed, success } = await checkAttachment(attachment.hash);
|
||||
this._changeWorkingStatus(
|
||||
attachment.hash,
|
||||
undefined,
|
||||
success ? undefined : failed
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this._changeWorkingStatus(attachment.hash);
|
||||
if (e instanceof Error)
|
||||
showToast("error", `Rechecking failed: ${e.message}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
id: "checking-attachments",
|
||||
title: "Checking attachments"
|
||||
});
|
||||
};
|
||||
|
||||
rename = async (hash: string, newName: string) => {
|
||||
|
||||
Reference in New Issue
Block a user