From 8b799755003a31e7d765f6cc07f9c533b78c6e08 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 18 Jul 2024 19:29:34 +0300 Subject: [PATCH] server: Fix SVG backwards compatibility (fixes #238) --- src/becca/entities/bnote.ts | 2 +- src/routes/api/image.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index edb7f67e3..a1d4cf395 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -1151,7 +1151,7 @@ class BNote extends AbstractBeccaEntity { .map(row => new BAttachment(row)); } - getAttachmentByTitle(title: string): BAttachment { + getAttachmentByTitle(title: string): BAttachment | undefined { // cannot use SQL to filter by title since it can be encrypted return this.getAttachments().filter(attachment => attachment.title === title)[0]; } diff --git a/src/routes/api/image.ts b/src/routes/api/image.ts index 0c6f29124..926ad3ead 100644 --- a/src/routes/api/image.ts +++ b/src/routes/api/image.ts @@ -44,9 +44,8 @@ function renderSvgAttachment(image: BNote | BRevision, res: Response, attachment let svg: string | Buffer = '' const attachment = image.getAttachmentByTitle(attachmentName); - const content = attachment.getContent(); if (attachment) { - svg = content; + svg = attachment.getContent(); } else { // backwards compatibility, before attachments, the SVG was stored in the main note content as a separate key const contentSvg = image.getJsonContentSafely()?.svg;