c6945bd89e
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { prisma } from "@/lib/db";
|
|
|
|
const DEFAULTS: Record<string, string> = {
|
|
"monitor.enabled": "false",
|
|
"monitor.pollIntervalHours": "24",
|
|
"monitor.retryIntervalHours": "6",
|
|
"monitor.qualityCutoff": "2",
|
|
"monitor.upgradeWindowDays": "14",
|
|
"floor.jobDelaySeconds": "0",
|
|
};
|
|
|
|
export async function GET() {
|
|
const rows = await prisma.config.findMany({ where: { key: { in: Object.keys(DEFAULTS) } } });
|
|
const stored = Object.fromEntries(rows.map((r) => [r.key, r.value]));
|
|
return Response.json(
|
|
Object.fromEntries(Object.entries(DEFAULTS).map(([k, d]) => [k, stored[k] ?? d])),
|
|
);
|
|
}
|
|
|
|
export async function PATCH(request: Request) {
|
|
let body: unknown;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return Response.json({ error: "invalid JSON" }, { status: 400 });
|
|
}
|
|
const entries = Object.entries((body ?? {}) as Record<string, unknown>).filter(
|
|
([k]) => Object.prototype.hasOwnProperty.call(DEFAULTS, k),
|
|
);
|
|
for (const [key, value] of entries) {
|
|
await prisma.config.upsert({
|
|
where: { key },
|
|
create: { key, value: String(value), secret: false },
|
|
update: { value: String(value) },
|
|
});
|
|
}
|
|
return Response.json({ updated: entries.length });
|
|
}
|