import { analyseMedia, probeMedia } from "@/lib/media"; import { resolveInRoots } from "@/lib/paths"; export const dynamic = "force-dynamic"; // One track, opened: what it is, and what it sounds like. // // The analysis is the expensive half (a full decode) and is cached by mtime, so // this is slow exactly once per file and instant afterwards. Both halves come // back together because the bench cannot draw a lane without either. export async function GET(request: Request) { const url = new URL(request.url); const abs = resolveInRoots(url.searchParams.get("path")); if (!abs) return Response.json({ error: "path is not inside a known root" }, { status: 400 }); try { const info = await probeMedia(abs); if (!info.hasAudio) { return Response.json({ info, analysis: null, error: "no audio track" }, { headers: { "cache-control": "no-store" }, }); } const analysis = await analyseMedia(abs); return Response.json({ info, analysis }, { headers: { "cache-control": "no-store" } }); } catch (err) { return Response.json({ error: String((err as Error)?.message ?? err) }, { status: 500 }); } }