fix(api): 🐛 Fix Cloudflare R2 incorrectly serving SVG images as XML

This commit is contained in:
Jesse Wierzbinski 2024-06-16 01:50:32 -10:00
parent de9dca5735
commit 65498e7bd7
No known key found for this signature in database

View file

@ -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 = const realFilename =
media.headers media.headers
.get("Content-Disposition") .get("Content-Disposition")