🛠️ Update svgs/svgr API endpoint to use custom parseReact utility with SWC

This commit is contained in:
pheralb
2025-08-27 19:31:23 +01:00
parent 43b6173c0e
commit b85cc58db3
+33
View File
@@ -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 },
);
}
};