From 65498e7bd74a61fe06e73e1a585d0cc377993584 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 16 Jun 2024 01:50:32 -1000 Subject: [PATCH] fix(api): :bug: Fix Cloudflare R2 incorrectly serving SVG images as XML --- server/api/media/proxy/:id.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/api/media/proxy/:id.ts b/server/api/media/proxy/:id.ts index 7fba6c40..be294061 100644 --- a/server/api/media/proxy/:id.ts +++ b/server/api/media/proxy/:id.ts @@ -46,6 +46,15 @@ export default (app: Hono) => }, }); + // Check if file extension ends in svg or svg + // Cloudflare R2 serves those as application/xml + if ( + media.headers.get("Content-Type") === "application/xml" && + id.endsWith(".svg") + ) { + media.headers.set("Content-Type", "image/svg+xml"); + } + const realFilename = media.headers .get("Content-Disposition")