feat: extend agent-driven map workbench
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
MAX_CONDUIT_FEATURES,
|
||||
MAX_MAP_FEATURE_IDS,
|
||||
createMapFeatureWfsUrl,
|
||||
normalizeMapFeatureCollection,
|
||||
parseMapFeatureQuery
|
||||
} from "@/features/workbench/map/map-feature-query";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const parsed = parseMapFeatureQuery(await request.json().catch(() => null));
|
||||
if (!parsed.ok) {
|
||||
return NextResponse.json({ code: parsed.code }, { status: parsed.status });
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(createMapFeatureWfsUrl(parsed.value), {
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(8_000)
|
||||
});
|
||||
const collection = normalizeMapFeatureCollection(
|
||||
await response.json(),
|
||||
parsed.value.featureIds ? MAX_MAP_FEATURE_IDS : MAX_CONDUIT_FEATURES
|
||||
);
|
||||
if (!response.ok || !collection) throw new Error("Invalid WFS response");
|
||||
return NextResponse.json(collection);
|
||||
} catch {
|
||||
return NextResponse.json({ code: "WFS_UNAVAILABLE" }, { status: 502 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user