import { NextResponse } from "next/server"; import { z } from "zod"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { getDownloadSpeedLimit, getRecommendedRoles, saveDownloadSpeedLimit, saveRecommendedRoles, SettingsError } from "@/lib/settings"; export const dynamic = "force-dynamic"; async function current() { return { recommendedRoles: await getRecommendedRoles(), maxBytesPerSecond: await getDownloadSpeedLimit() }; } /** Download settings: which file kinds are picked along with model weights, and the speed limit. */ export const GET = withAuth(async () => NextResponse.json(await current())); const Body = z.object({ recommendedRoles: z.array(z.string()).max(32).optional(), maxBytesPerSecond: z.number().nullable().optional(), }); export const PUT = withAuth(async (req) => { try { const body = Body.parse(await req.json()); if (body.recommendedRoles) await saveRecommendedRoles(body.recommendedRoles); if (body.maxBytesPerSecond !== undefined) await saveDownloadSpeedLimit(body.maxBytesPerSecond); return NextResponse.json(await current()); } catch (err) { if (err instanceof SettingsError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });