import { publicBaseUrl } from '@/lib/config'; import { encodeScreen } from '@/lib/screen/encode'; import { parsePreviewTime } from '@/lib/screen/preview-time'; import { renderScreenSvg } from '@/lib/screen/render'; import { buildCurrentScreen } from '@/lib/screen/service'; export const dynamic = 'force-dynamic'; /** * The panel as it stands, or as it will stand at a given moment. * * Deliberately the same pipeline the device is served from — payload, SVG, * threshold — so what the admin sees is what the shop window shows, down to * the last thresholded pixel. A preview drawn any other way would eventually * disagree with reality, and quietly. * * `?at=` moves the clock. The whole pipeline is already a function of "now", * so showing next Tuesday costs nothing but passing a different instant — * which is how a holiday closure can be checked before anyone is standing in * front of a locked door. * * Behind /api/admin, so the middleware requires a session. */ export async function GET(request: Request) { const { at } = parsePreviewTime(new URL(request.url).searchParams.get('at'), new Date()); const { payload } = await buildCurrentScreen(at, publicBaseUrl(request)); const png = encodeScreen(await renderScreenSvg(payload), 'png'); return new Response(new Uint8Array(png), { headers: { 'Content-Type': 'image/png', // It reflects live data; a cached preview is a misleading preview. 'Cache-Control': 'no-store', }, }); }