feat: establish NekoNest Cloud control and relay
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { getCloudViewer } from "@/app/cloud-auth";
|
||||
import { resolveBetaAccessRequest } 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<{
|
||||
requestId?: string;
|
||||
action?: "approve" | "decline";
|
||||
capacitySlots?: number;
|
||||
endsAt?: string;
|
||||
response?: string;
|
||||
reason?: string;
|
||||
idempotencyKey?: string;
|
||||
}>(request);
|
||||
const result = await resolveBetaAccessRequest({
|
||||
actorId: viewer.userId,
|
||||
requestId: payload.requestId ?? "",
|
||||
action: payload.action ?? "decline",
|
||||
capacitySlots: payload.capacitySlots ?? 0,
|
||||
endsAt: payload.endsAt ?? "",
|
||||
response: payload.response ?? "",
|
||||
reason: payload.reason ?? "",
|
||||
idempotencyKey: payload.idempotencyKey ?? "",
|
||||
});
|
||||
return Response.json(result);
|
||||
} catch (error) {
|
||||
return apiError(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user