import { recordDiscovered } from "@/lib/camera-registry"; import { discoverCameras, discoverRequestSchema } from "@/lib/onvif"; export async function POST(request: Request) { // An empty body means "use the defaults". const body = await request.json().catch(() => ({})); const parsed = discoverRequestSchema.safeParse(body ?? {}); if (!parsed.success) { return Response.json({ error: "Invalid scan options" }, { status: 400 }); } const { timeout, unicastSweep } = parsed.data; try { const cameras = await discoverCameras({ timeoutMs: timeout, unicastSweep }); await recordDiscovered(cameras); return Response.json({ cameras }); } catch (err) { // OS and socket errors can carry interface names and addresses; keep them in the server log. console.error("Network scan failed", err); return Response.json({ error: "Network scan failed" }, { status: 500 }); } }