File size: 893 Bytes
88c4c60 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import { NextResponse } from "next/server";
import { FILTERS } from "./filters.js";
export const dynamic = "force-dynamic";
export async function GET(request) {
const { searchParams } = new URL(request.url);
const url = searchParams.get("url");
const type = searchParams.get("type");
if (!url || !type) {
return NextResponse.json({ error: "Missing url or type" }, { status: 400 });
}
const filter = FILTERS[type];
if (!filter) {
return NextResponse.json({ error: "Unknown filter type" }, { status: 400 });
}
try {
const res = await fetch(url);
if (!res.ok) {
return NextResponse.json({ data: [] });
}
const json = await res.json();
const raw = json.data ?? json.models ?? json;
const data = filter(Array.isArray(raw) ? raw : []);
return NextResponse.json({ data });
} catch {
return NextResponse.json({ data: [] });
}
}
|