From b85cc58db302f90b55629b853eefcdc2908916b5 Mon Sep 17 00:00:00 2001 From: pheralb Date: Wed, 27 Aug 2025 19:31:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Update=20svgs/svgr=20AP?= =?UTF-8?q?I=20endpoint=20to=20use=20custom=20parseReact=20utility=20with?= =?UTF-8?q?=20SWC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/api/svgs/svgr/+server.ts | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/routes/api/svgs/svgr/+server.ts diff --git a/src/routes/api/svgs/svgr/+server.ts b/src/routes/api/svgs/svgr/+server.ts new file mode 100644 index 0000000..a6f37b4 --- /dev/null +++ b/src/routes/api/svgs/svgr/+server.ts @@ -0,0 +1,33 @@ +import type { RequestEvent } from "@sveltejs/kit"; +import { json, redirect } from "@sveltejs/kit"; + +import { optimizeSvg } from "@/utils/optimizeSvg"; +import { parseReactSvgContent } from "@/utils/parseReactSvgContent"; + +export const GET = async () => { + return redirect(301, "https://svgl.app/api"); +}; + +export const POST = async ({ request }: RequestEvent) => { + try { + const body = await request.json(); + + const svgCode = body.code; + const typescript = body.typescript; + const name = body.name.replace(/[^a-zA-Z0-9]/g, ""); + const optimizedSvg = optimizeSvg({ svgCode }); + + const code = await parseReactSvgContent({ + componentName: name, + svgCode: optimizedSvg, + typescript, + }); + + return json({ data: code }, { status: 200 }); + } catch (error) { + return json( + { error: `⚠️ api/svgs/svgr - Error: ${error}` }, + { status: 500 }, + ); + } +};