feat: establish NekoNest Cloud control and relay

This commit is contained in:
2026-08-12 23:25:43 +08:00
commit f27606b709
222 changed files with 71456 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
import { getCloudViewer } from "@/app/cloud-auth";
import {
cancelAccountDeletion,
DomainError,
getOrCreateAccount,
requestAccountDeletion,
} 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, headers: { "cache-control": "no-store" } },
);
}
const payload = await readJsonMutation<{
action?: string;
requestId?: string;
confirmed?: boolean;
reason?: string;
idempotencyKey?: string;
}>(request);
const account = await getOrCreateAccount(viewer);
if (payload.action === "request") {
const deletionRequest = await requestAccountDeletion({
accountId: account.id,
actorId: viewer.userId,
confirmed: payload.confirmed === true,
reason: payload.reason ?? "",
idempotencyKey: payload.idempotencyKey ?? "",
});
return Response.json(
{ deletionRequest },
{ status: 201, headers: { "cache-control": "no-store" } },
);
}
if (payload.action === "cancel") {
const deletionRequest = await cancelAccountDeletion({
accountId: account.id,
actorId: viewer.userId,
requestId: payload.requestId ?? "",
});
return Response.json(
{ deletionRequest },
{ headers: { "cache-control": "no-store" } },
);
}
throw new DomainError(
"invalid_deletion_action",
"请选择有效的注销申请操作",
);
} catch (error) {
const response = apiError(error);
response.headers.set("cache-control", "no-store");
return response;
}
}