From 0c37b2ce5cbc33c6084c29ffa3ab6baa0e3640c9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 27 Mar 2026 23:13:40 +0200 Subject: [PATCH] fix(export/single): crash due to use of Buffer --- packages/trilium-core/src/services/export/single.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/trilium-core/src/services/export/single.ts b/packages/trilium-core/src/services/export/single.ts index 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)}"`;