import { NextResponse } from "next/server"; import { createBindUrl, ensureDeviceRegistration } from "@/lib/monitor-data"; export async function POST(request: Request) { const body = (await request.json().catch(() => null)) as | { deviceUuid?: string; displayName?: string; appVersion?: string; } | null; if (!body?.deviceUuid || typeof body.deviceUuid !== "string") { return NextResponse.json( { error: "deviceUuid 是必填项。" }, { status: 400 }, ); } try { const device = await ensureDeviceRegistration({ deviceUuid: body.deviceUuid, displayName: typeof body.displayName === "string" ? body.displayName : undefined, appVersion: typeof body.appVersion === "string" ? body.appVersion : undefined, }); return NextResponse.json({ deviceUuid: device.deviceUuid, bindUrl: createBindUrl(device.deviceUuid), }); } catch (error) { return NextResponse.json( { error: error instanceof Error ? error.message : "设备注册失败,请稍后再试。", }, { status: 500 }, ); } }