fix: convert SVG avatar into PNG on save and serve (#20654)

This commit is contained in:
Omar López authored and GitHub committed 2025-04-11 08:14:01 -07:00
1 parent 2ab34004a2
commit 821bd37b37
6 files changed
+61 -9

No files matched your search

+14 -1
View File
@@ -5,6 +5,7 @@ import { NextResponse } from "next/server";
import { z } from "zod";
import { AVATAR_FALLBACK, WEBAPP_URL } from "@calcom/lib/constants";
import { convertSvgToPng } from "@calcom/lib/server/imageUtils";
import prisma from "@calcom/prisma";
const querySchema = z.object({
@@ -44,7 +45,19 @@ async function handler(req: NextRequest, { params }: { params: Promise<Params> }
data: true,
},
});
img = data;
// Convert SVG to PNG if needed and update the database
if (data.startsWith("data:image/svg+xml;base64,")) {
const pngData = await convertSvgToPng(data);
await prisma.avatar.update({
where: { objectKey },
data: { data: pngData },
});
img = pngData;
} else {
img = data;
}
} catch (e) {
// If anything goes wrong or avatar is not found, use default avatar
const url = new URL(AVATAR_FALLBACK, WEBAPP_URL).toString();