mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 09:15:49 +02:00
fix(export/single): crash due to use of Buffer
This commit is contained in:
@@ -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)}"`;
|
||||
|
||||
Reference in New Issue
Block a user