Discovers ONVIF cameras (Hikvision/Annke) over WS-Discovery, keeps a server-side registry and an encrypted credential store, and serves info, snapshot and credentials routes for each camera. The home page is now a Server Component that lists known cameras from the registry on load, without a scan (vrek iss-a0hz0py). The snapshot refresh rate lives in the URL (?refresh=), and a scan refreshes the server-rendered list. Route input is validated with zod (iss-rjqy3hy), and /api/discover no longer returns raw error messages (iss-dbwgww8). Adds @tanstack/react-query and zod as dependencies, with a QueryClient provider in the root layout. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
23 lines
906 B
TypeScript
23 lines
906 B
TypeScript
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 });
|
|
}
|
|
}
|