color category icon

This commit is contained in:
hamid zarghami
2026-02-13 16:18:57 +03:30
parent 0ff035b6b4
commit 9a1d796b90
2 changed files with 120 additions and 4 deletions
+46
View File
@@ -0,0 +1,46 @@
import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export const revalidate = 0;
const CACHE_MAX_AGE = "public, max-age=3600";
export async function GET(request: NextRequest) {
const url = request.nextUrl.searchParams.get("url");
if (!url) {
return NextResponse.json({ error: "url is required" }, { status: 400 });
}
try {
const parsed = new URL(url);
if (!["http:", "https:"].includes(parsed.protocol)) {
return NextResponse.json({ error: "Invalid URL" }, { status: 400 });
}
const res = await fetch(url, {
headers: { Accept: "image/svg+xml, text/xml, text/plain" },
});
if (!res.ok) {
return NextResponse.json(
{ error: "Failed to fetch SVG" },
{ status: res.status }
);
}
const text = await res.text();
if (!text.trim().toLowerCase().includes("<svg")) {
return NextResponse.json(
{ error: "Response is not SVG" },
{ status: 400 }
);
}
return new NextResponse(text, {
headers: {
"Content-Type": "image/svg+xml",
"Cache-Control": CACHE_MAX_AGE,
},
});
} catch {
return NextResponse.json(
{ error: "Failed to fetch SVG" },
{ status: 502 }
);
}
}