fix(export/single): crash due to use of Buffer

This commit is contained in:
Elian Doran
2026-03-27 23:13:40 +02:00
parent 73f401f106
commit 0c37b2ce5c

View File

@@ -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)}"`;