import { clientIp, isAdminNetworkAllowed, json, readJsonBody } from "../../../_lib/auth"; import { readSettings, validTvId } from "../../../_lib/store"; import { recordTvCheckIn } from "../../../_lib/tvs"; export const dynamic = "force-dynamic"; type Report = { device?: string; kind?: string; ok?: boolean; detail?: string; applied?: string; app?: string }; /** The Shield photo app reports the outcome of its morning routine here (shown in admin). */ export async function POST(request: Request) { if (!isAdminNetworkAllowed(request.headers)) return new Response("Not found", { status: 404 }); const body = await readJsonBody(request); const id = validTvId(body?.device); if (!body || !id) return json({ error: "Missing or invalid device id." }, 400); const settings = await readSettings(); await recordTvCheckIn( id, { appVersion: body.app, appliedVersion: body.applied, ip: clientIp(request.headers) }, { kind: body.kind || "event", ok: body.ok === true, detail: body.detail || "" }, new Set(settings.tvs.map((tv) => tv.id)), ); return json({ ok: true }); }