46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { upsertDeviceHeartbeat } from "@/lib/boss-data";
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const body = (await request.json()) as {
|
|
deviceId?: string;
|
|
token?: string;
|
|
pairingCode?: string;
|
|
name?: string;
|
|
avatar?: string;
|
|
account?: string;
|
|
status?: "online" | "abnormal" | "offline";
|
|
quota5h?: number;
|
|
quota7d?: number;
|
|
projects?: string[];
|
|
endpoint?: string;
|
|
};
|
|
|
|
if (
|
|
!body.deviceId ||
|
|
!body.name ||
|
|
!body.avatar ||
|
|
!body.account ||
|
|
!body.status ||
|
|
!body.projects
|
|
) {
|
|
return NextResponse.json({ ok: false, message: "heartbeat 字段不完整" }, { status: 400 });
|
|
}
|
|
|
|
const device = await upsertDeviceHeartbeat({
|
|
deviceId: body.deviceId,
|
|
token: body.token,
|
|
pairingCode: body.pairingCode,
|
|
name: body.name,
|
|
avatar: body.avatar,
|
|
account: body.account,
|
|
status: body.status,
|
|
quota5h: body.quota5h ?? 0,
|
|
quota7d: body.quota7d ?? 0,
|
|
projects: body.projects,
|
|
endpoint: body.endpoint,
|
|
});
|
|
|
|
return NextResponse.json({ ok: true, ...device });
|
|
}
|