A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: add support for exporting locked notes
Abdullah Attacafd854b8c28
diff --git a/apps/web/src/common/export.ts b/apps/web/src/common/export.tsindex a23da7996..428316693 100644--- a/apps/web/src/common/export.ts+++ b/apps/web/src/common/export.ts@@ -23,6 +23,7 @@ import { zip } from "../utils/zip";import { saveAs } from "file-saver";import { showToast } from "../utils/toast";import { sanitizeFilename } from "@notesnook/common";+import Vault from "./vault";export async function exportToPDF(title: string,@@ -54,30 +55,58 @@ export async function exportNotes(title: "Exporting notes",subtitle: "Please wait while your notes are exported.",action: async (report) => {- if (format === "pdf") {- const note = db.notes?.note(noteIds[0]);- if (!note) return false;- const html = await note.export("html");- if (!html) return false;- return await exportToPDF(note.title, html);- }+ let vaultUnlocked = false;++ if (noteIds.length === 1 && db.notes?.note(noteIds[0])?.data.locked) {+ vaultUnlocked = await Vault.unlockVault();+ if (!vaultUnlocked) return false;+ } else if (noteIds.length > 1 && (await db.vault?.exists()))+ vaultUnlocked = await Vault.unlockVault();++ if (!vaultUnlocked)+ showToast(+ "error",+ "Failed to unlock vault. Locked notes will be skipped."+ );const files = [];let index = 0;for (const noteId of noteIds) {const note = db.notes?.note(noteId);if (!note) continue;+ if (!vaultUnlocked && note.data.locked) continue;+report({current: ++index,total: noteIds.length,text: `Exporting "${note.title}"...`});- const content = await note.export(format).catch((e: Error) => {- showToast("error", e.message);- });- if (!content) continue;- files.push({ filename: note.title, content });+ const rawContent = await db.content?.raw(note.data.contentId);+ const content = note.data.locked+ ? await db.vault?.decryptContent(rawContent)+ : rawContent;++ const exported = await note+ .export(format === "pdf" ? "html" : format, content)+ .catch((e: Error) => {+ console.error(note.data, e);+ showToast(+ "error",+ `Failed to export note "${note.title}": ${e.message}`+ );+ });++ if (typeof exported !== "string") {+ showToast("error", `Failed to export note "${note.title}"`);+ continue;+ }++ if (format === "pdf") {+ return await exportToPDF(note.title, exported);+ }++ files.push({ filename: note.title, content: exported });}if (!files.length) return false;@@ -90,6 +119,7 @@ export async function exportNotes(const zipped = await zip(files, format);saveAs(new Blob([zipped.buffer]), "notes.zip");}+return true;}});diff --git a/apps/web/src/common/vault.js b/apps/web/src/common/vault.jsindex 1f6fbd2e9..413b8918f 100644--- a/apps/web/src/common/vault.js+++ b/apps/web/src/common/vault.js@@ -55,8 +55,12 @@ class Vault {);}+ /**+ *+ * @returns {Promise<boolean>}+ */static unlockVault() {- return showPasswordDialog("lock_note", ({ password }) => {+ return showPasswordDialog("ask_vault_password", ({ password }) => {return db.vault.unlock(password).then(() => true)diff --git a/apps/web/src/components/note/index.jsx b/apps/web/src/components/note/index.jsxindex 958630931..743179801 100644--- a/apps/web/src/components/note/index.jsx+++ b/apps/web/src/components/note/index.jsx@@ -33,6 +33,7 @@ import {PDF,Markdown,HTML,+ Text as Plaintext,Readonly,StarOutline,AddReminder,@@ -331,7 +332,7 @@ const formats = [{type: "txt",title: "Text",- icon: Text,+ icon: Plaintext,subtitle: "Can be opened in any plain-text editor."}];@@ -419,7 +420,6 @@ const menuItems = [title: "Print",disabled: ({ note }) => {if (!db.notes.note(note.id).synced()) return notFullySyncedText;- if (note.locked) return "Locked notes cannot be printed.";},icon: Print,onClick: async ({ note }) => {@@ -448,7 +448,6 @@ const menuItems = [icon: Export,disabled: ({ note }) => {if (!db.notes.note(note.id).synced()) return notFullySyncedText;- if (note.locked) return "Locked notes cannot be exported currently.";},items: formats.map((format) => ({key: format.type,