web: use simple transform stream for export progress

This commit is contained in:
Abdullah Atta
2024-01-17 21:43:21 +05:00
parent becc00d2ee
commit 2bb3652be2
2 changed files with 16 additions and 5 deletions

View File

@@ -86,13 +86,24 @@ export async function exportNotes(
title: "Exporting notes",
subtitle: "Please wait while your notes are exported.",
action: async (report) => {
const total = await notes.count();
let progress = 0;
const noteStream = fromAsyncIterator(notes[Symbol.asyncIterator]());
await noteStream
.pipeThrough(
new ExportStream(format, undefined, (c, text) =>
report({ current: c, text })
)
new TransformStream<Note, Note>({
transform(note, controller) {
controller.enqueue(note);
report({
total,
current: progress++,
text: `Exporting "${note?.title}"`
});
}
})
)
.pipeThrough(new ExportStream(format, undefined))
.pipeThrough(createZipStream())
.pipeTo(await createWriteStream("notes.zip"));
return true;

View File

@@ -37,9 +37,9 @@ export class ExportStream extends TransformStream<Note, ZipFile> {
return;
}
if (!note || format === "pdf") return;
if (format === "pdf") return;
const result = await exportNote(note, format);
const result = await exportNote(note, { format });
if (!result) return;
const { filename, content } = result;