mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
🛠️ Update svgs/svgr API endpoint to use custom parseReact utility with SWC
This commit is contained in:
@@ -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 },
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user