Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(export/single): crash due to use of Buffer
Elian Doran0c37b2ce5cbc
diff --git a/packages/trilium-core/src/services/export/single.ts b/packages/trilium-core/src/services/export/single.tsindex b1ea35260e..301112825c 100644--- a/packages/trilium-core/src/services/export/single.ts+++ b/packages/trilium-core/src/services/export/single.ts@@ -11,6 +11,7 @@ import type TaskContext from "../task_context.js";import { escapeHtml,getContentDisposition } from "../utils/index.js";import mdService from "./markdown.js";import { ExportFormat } from "../../meta.js";+import { encodeBase64 } from "../utils/binary.js";function exportSingleNote(taskContext: TaskContext<"export">, branch: BBranch, format: ExportFormat, res: Response) {const note = branch.getNote();@@ -88,11 +89,11 @@ function inlineAttachments(content: string) {}const imageContent = note.getContent();- if (!Buffer.isBuffer(imageContent)) {+ if (typeof imageContent === "string") {return match;}- const base64Content = imageContent.toString("base64");+ const base64Content = encodeBase64(imageContent);const srcValue = `data:${note.mime};base64,${base64Content}`;return `src="${srcValue}"`;@@ -105,11 +106,11 @@ function inlineAttachments(content: string) {}const attachmentContent = attachment.getContent();- if (!Buffer.isBuffer(attachmentContent)) {+ if (typeof attachmentContent === "string") {return match;}- const base64Content = attachmentContent.toString("base64");+ const base64Content = encodeBase64(attachmentContent);const srcValue = `data:${attachment.mime};base64,${base64Content}`;return `src="${srcValue}"`;@@ -122,11 +123,11 @@ function inlineAttachments(content: string) {}const attachmentContent = attachment.getContent();- if (!Buffer.isBuffer(attachmentContent)) {+ if (typeof attachmentContent === "string") {return match;}- const base64Content = attachmentContent.toString("base64");+ const base64Content = encodeBase64(attachmentContent);const hrefValue = `data:${attachment.mime};base64,${base64Content}`;return `href="${hrefValue}" download="${escapeHtml(attachment.title)}"`;