15 lines
684 B
TypeScript
15 lines
684 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { cleanupIdleNodeModules } from "../../../../lib/cleanup";
|
|
import { errorResponse } from "../../../../lib/http";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json().catch(() => ({}));
|
|
const idleHours = body.idleHours === undefined ? undefined : Number(body.idleHours);
|
|
if (idleHours !== undefined && (!Number.isFinite(idleHours) || idleHours < 0)) throw new Error("idleHours must be a non-negative number");
|
|
return NextResponse.json(await cleanupIdleNodeModules(idleHours));
|
|
} catch (error) { return errorResponse(error); }
|
|
}
|