v0.11.1: 权限体系重构 + AI管线优化 + 内容整理
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { requireAdmin } from "@/lib/admin-auth";
|
||||
|
||||
export async function GET() {
|
||||
const authError = await requireAdmin();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const configs = await prisma.systemConfig.findMany();
|
||||
const result: Record<string, unknown> = {};
|
||||
for (const c of configs) {
|
||||
result[c.key] = c.value;
|
||||
}
|
||||
return NextResponse.json(result);
|
||||
} catch (error: unknown) {
|
||||
const err = error as { message?: string };
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
const authError = await requireAdmin();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
const results: string[] = [];
|
||||
|
||||
for (const [key, value] of Object.entries(body)) {
|
||||
await prisma.systemConfig.upsert({
|
||||
where: { key },
|
||||
update: { value: value as any },
|
||||
create: { key, value: value as any },
|
||||
});
|
||||
results.push(key);
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, updated: results });
|
||||
} catch (error: unknown) {
|
||||
const err = error as { message?: string };
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user