Files
nekonest-cloud/app/api/admin/beta/route.ts
T

15 lines
959 B
TypeScript

import { getCloudViewer } from "@/app/cloud-auth";
import { setPublicBeta } from "@/db/repository";
import { apiError, readJsonMutation } from "../../respond";
export async function POST(request: Request) {
try {
const viewer = await getCloudViewer();
if (!viewer) return Response.json({ error: "authentication_required", message: "请先登录" }, { status: 401 });
if (!viewer.isAdmin) return Response.json({ error: "forbidden", message: "没有商业后台权限" }, { status: 403 });
const payload = await readJsonMutation<{ enabled?: boolean; capacitySlots?: number | null; reason?: string; idempotencyKey?: string }>(request);
const beta = await setPublicBeta({ actorId: viewer.userId, enabled: payload.enabled ?? false, capacitySlots: payload.capacitySlots ?? null, reason: payload.reason ?? "", idempotencyKey: payload.idempotencyKey ?? "" });
return Response.json({ beta });
} catch (error) { return apiError(error); }
}