import { NextResponse } from "next/server"; import { findPython310, getInstalledHeadroomExtras, HEADROOM_COMPRESSION_EXTRAS } from "@/lib/headroom/detect"; import { installHeadroomExtras } from "@/lib/headroom/process"; export const dynamic = "force-dynamic"; export async function GET() { try { const python = findPython310(); const status = getInstalledHeadroomExtras(python); return NextResponse.json({ available: HEADROOM_COMPRESSION_EXTRAS, ...status, }); } catch (error) { return NextResponse.json({ error: error.message }, { status: 500 }); } } export async function POST(req) { try { const body = await req.json().catch(() => ({})); const requested = Array.isArray(body?.extras) ? body.extras : []; const result = await installHeadroomExtras(requested); return NextResponse.json(result); } catch (error) { const status = error.code === "NOT_INSTALLED" || error.code === "NO_PYTHON" ? 400 : 500; return NextResponse.json({ error: error.message, code: error.code || null }, { status }); } }