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
+23
View File
@@ -0,0 +1,23 @@
import { env } from "cloudflare:workers";
import { getCloudViewer } from "@/app/cloud-auth";
import { createPhoneHandoffTicket } from "@/db/relay-control-plane";
import { DomainError, getOrCreateAccount } from "@/db/repository";
import { apiError } from "../../respond";
export async function POST() {
try {
const viewer = await getCloudViewer();
if (!viewer) throw new DomainError("authentication_required", "请先登录", 401);
const pwaOrigin = env.NEKONEST_CLOUD_PWA_ORIGIN?.trim() ?? "";
if (!pwaOrigin) {
throw new DomainError("pwa_handoff_unavailable", "Cloud PWA 地址尚未配置", 503, true, 30);
}
const account = await getOrCreateAccount(viewer);
return Response.json(
await createPhoneHandoffTicket({ accountId: account.id, pwaOrigin }),
{ status: 201, headers: { "cache-control": "no-store" } },
);
} catch (error) {
return apiError(error);
}
}