feat: establish NekoNest Cloud control and relay
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user