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
chore(core): fix type issue
Elian Doran3b437d85c822
diff --git a/packages/trilium-core/src/routes/api/attachments.ts b/packages/trilium-core/src/routes/api/attachments.tsindex d361b5698a..1bd926ed88 100644--- a/packages/trilium-core/src/routes/api/attachments.ts+++ b/packages/trilium-core/src/routes/api/attachments.ts@@ -8,6 +8,7 @@ type FileRequest<P> = Omit<Request<P>, "file"> & { file?: File };import becca from "../../becca/becca.js";import blobService from "../../services/blob.js";import imageService from "../../services/image.js";+import { wrapStringOrBuffer } from "../../services/utils/binary.js";function getAttachmentBlob(req: Request<{ attachmentId: string }>) {const preview = req.query.preview === "true";@@ -60,8 +61,11 @@ function uploadAttachment(req: FileRequest<{ noteId: string }>) {const note = becca.getNoteOrThrow(noteId);let url;+ // Convert buffer to Uint8Array (Buffer extends Uint8Array, string needs encoding)+ const buffer = wrapStringOrBuffer(file.buffer as string | Uint8Array);+if (["image/png", "image/jpg", "image/jpeg", "image/gif", "image/webp", "image/svg+xml"].includes(file.mimetype)) {- const attachment = imageService.saveImageToAttachment(noteId, file.buffer, file.originalname, true, true);+ const attachment = imageService.saveImageToAttachment(noteId, buffer, file.originalname, true, true);url = `api/attachments/${attachment.attachmentId}/image/${encodeURIComponent(attachment.title)}`;} else {const attachment = note.saveAttachment({