From ea1da1e1550d0e75d9823d199bc06fe989726dd9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 16 Jul 2024 22:29:00 +0300 Subject: [PATCH] server: Fix rendering of SVG attachments (closes #226) --- src/routes/api/image.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/routes/api/image.ts b/src/routes/api/image.ts index b00c7fd7f..0c6f29124 100644 --- a/src/routes/api/image.ts +++ b/src/routes/api/image.ts @@ -41,22 +41,21 @@ function returnImageInt(image: BNote | BRevision | null, res: Response) { } function renderSvgAttachment(image: BNote | BRevision, res: Response, attachmentName: string) { - let svgString = '' + let svg: string | Buffer = '' const attachment = image.getAttachmentByTitle(attachmentName); const content = attachment.getContent(); - if (attachment && typeof content === "string") { - svgString = content; + if (attachment) { + svg = content; } else { // backwards compatibility, before attachments, the SVG was stored in the main note content as a separate key const contentSvg = image.getJsonContentSafely()?.svg; if (contentSvg) { - svgString = contentSvg; + svg = contentSvg; } } - const svg = svgString res.set('Content-Type', "image/svg+xml"); res.set("Cache-Control", "no-cache, no-store, must-revalidate"); res.send(svg);