9router/src/app/api/headroom/extras/route.js
decolua 74d5fedf79 feat(headroom): activate/uninstall extras + fix interpreter detection
- find interpreter next to headroom binary so extras/version read correctly
- add on/off toggle to activate [code]/[ml] via proxy restart
- add uninstall action + live install log progress + ~1GB confirm modal
2026-07-10 17:32:45 +07:00

46 lines
1.8 KiB
JavaScript

import { NextResponse } from "next/server";
import { findPython310, getInstalledHeadroomExtras, HEADROOM_COMPRESSION_EXTRAS } from "@/lib/headroom/detect";
import { installHeadroomExtras, uninstallHeadroomExtras, getInstallLogTail } from "@/lib/headroom/process";
export const dynamic = "force-dynamic";
export async function GET(req) {
try {
// `?log=1` returns the live install/uninstall log tail for progress polling.
if (new URL(req.url).searchParams.get("log") === "1") {
return NextResponse.json({ log: getInstallLogTail() });
}
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 });
}
}
export async function DELETE(req) {
try {
const body = await req.json().catch(() => ({}));
const requested = Array.isArray(body?.extras) ? body.extras : [];
const result = await uninstallHeadroomExtras(requested);
return NextResponse.json(result);
} catch (error) {
const status = error.code === "NO_PYTHON" || error.code === "INVALID_EXTRAS" ? 400 : 500;
return NextResponse.json({ error: error.message, code: error.code || null }, { status });
}
}