mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
web: do not zip note without attachments on export
This commit is contained in:
@@ -33,6 +33,9 @@ import Vault from "./vault";
|
||||
import { ExportStream } from "../utils/streams/export-stream";
|
||||
import { showToast } from "../utils/toast";
|
||||
import { ConfirmDialog } from "../dialogs/confirm";
|
||||
import { db } from "./db";
|
||||
import { toAsyncIterator } from "@notesnook-importer/core/dist/src/utils/stream";
|
||||
import { saveAs } from "file-saver";
|
||||
|
||||
export async function exportToPDF(
|
||||
title: string,
|
||||
@@ -151,21 +154,37 @@ export async function exportNote(
|
||||
title: `Exporting "${note.title}"`,
|
||||
subtitle: "Please wait while your note is exported.",
|
||||
action: async (report) => {
|
||||
await fromAsyncIterator(
|
||||
const hasAttachments =
|
||||
(await db.relations.from(note, "attachment").count()) > 0;
|
||||
const stream = fromAsyncIterator(
|
||||
_exportNote(note, {
|
||||
format: options.format,
|
||||
unlockVault: Vault.unlockVault
|
||||
})
|
||||
)
|
||||
.pipeThrough(
|
||||
new ExportStream(report, (e) => showToast("error", e.message))
|
||||
)
|
||||
.pipeThrough(createZipStream())
|
||||
.pipeTo(
|
||||
await createWriteStream(
|
||||
`${sanitizeFilename(note.title, { replacement: "-" })}.zip`
|
||||
)
|
||||
);
|
||||
).pipeThrough(
|
||||
new ExportStream(report, (e) => {
|
||||
console.error(e);
|
||||
showToast("error", e.message);
|
||||
})
|
||||
);
|
||||
|
||||
if (hasAttachments) {
|
||||
await stream
|
||||
.pipeThrough(createZipStream())
|
||||
.pipeTo(
|
||||
await createWriteStream(
|
||||
`${sanitizeFilename(note.title, { replacement: "-" })}.zip`
|
||||
)
|
||||
);
|
||||
} else {
|
||||
for await (const file of toAsyncIterator(stream)) {
|
||||
if (typeof file.data === "string")
|
||||
saveAs(new Blob([Buffer.from(file.data, "utf-8")]), file.path);
|
||||
else if (file.data instanceof Uint8Array)
|
||||
saveAs(new Blob([file.data]), file.path);
|
||||
else await file.data.pipeTo(await createWriteStream(file.path));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user