import { NextResponse } from "next/server"; import Icon from "lucide-static"; import { toCamelCase } from "@/lib/utils"; export async function GET(req: Request) { try { const { searchParams: sp } = new URL(req.url); const iconInfo = { type: sp.get("type") === "svg" ? "svg" : "text", value: sp.get("value") || `sparkles`, width: Number(sp.get("w") || "128"), height: Number(sp.get("h") || "64"), animate: Boolean(sp.get("animate") === "true"), fillStyle: { fillType: sp.get("fillType") === "Solid" ? "Solid" : "Linear", primaryColor: sp.get("primaryColor") || "#FC466B", secondaryColor: sp.get("secondaryColor") || "#3F5EFB", angle: sp.get("angle") || "45", clip: Boolean(sp.get("clip") === "true"), }, background: { radialGlare: Boolean(sp.get("radialGlare") === "true"), noiseTexture: false, // TODO noiseOpacity: Number(sp.get("noiseOpacity") || "50"), radius: sp.get("radius") || "12", strokeSize: Number(sp.get("strokeSize") || "0"), strokeColor: sp.get("strokeColor") || "#FFFFFF", strokeOpacity: sp.get("strokeOpacity") || "100", }, icon: { color: sp.get("color") || "#FFFFFF", size: Number(sp.get("size") || "32"), family: sp.get("family") || "sans-serif", }, }; let svgString = ""; let svgClipString = ""; if (iconInfo.type === "svg") { const iconD = (Icon as { [key: string]: any })[ toCamelCase(iconInfo.value) ]; const regex = /(.*?)<\/svg>/; const match = iconD.match(regex); svgString = ` ${match?.[1]} `; svgClipString = ` ${match?.[1]} `; } let noiseImage = ""; if (iconInfo.background.noiseTexture) { // getImageData("http://localhost:3000/noise.png").then((data) => { // noiseImage = data as string; // }); } return new Response( ` ${ iconInfo.animate ? `` : "" } ${ iconInfo.animate ? `` : "" } ${ iconInfo.animate ? `` : "" } ${ iconInfo.type === "svg" && iconInfo.fillStyle.clip ? ` ${svgClipString} ` : "" } ${ iconInfo.background.noiseTexture ? ` ` : "" } ${ iconInfo.background.radialGlare ? `` : "" } ${ iconInfo.background.noiseTexture ? `` : "" } ${iconInfo.type === "svg" ? svgString : ""} ${ iconInfo.type === "text" ? ` ${iconInfo.value} ` : "" } ${ iconInfo.type === "gif" ? `` : "" } `, { status: 200, headers: { "Content-Type": "image/svg+xml", }, }, ); } catch (error) { return NextResponse.json({ message: "Something error" }, { status: 500 }); } }