家庭动态:老人/家属发言、三种可见范围,家庭内部内容不会播给老人。 共同照护:家庭备忘录、任务创建、认领、完成与交接记录。 用药闭环:计划、未来 7 天提醒实例、确认服用、延后、异常反馈。 风险闭环:红橙黄蓝分级、30 分钟去重、推送、认领、处理与误报记录。 报平安:家属发起、老人语音回应、状态同步。 Web 导航升级为守护、家庭、照护、陪伴、我的。 设备接口已升级为设备令牌认证,UUID 不再单独承担认证。
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { UsageEventType } from "@prisma/client";
|
|
import { NextResponse } from "next/server";
|
|
|
|
import { recordUsageEvent } from "@/lib/monitor-data";
|
|
import { requireDeviceAuth } from "@/lib/device-auth";
|
|
|
|
function toUsageEventType(rawType: unknown) {
|
|
switch (rawType) {
|
|
case UsageEventType.APP_OPEN:
|
|
return UsageEventType.APP_OPEN;
|
|
case UsageEventType.SETTINGS_OPENED:
|
|
return UsageEventType.SETTINGS_OPENED;
|
|
case UsageEventType.AI_SESSION_STARTED:
|
|
return UsageEventType.AI_SESSION_STARTED;
|
|
case UsageEventType.AI_SESSION_ENDED:
|
|
return UsageEventType.AI_SESSION_ENDED;
|
|
case UsageEventType.CAMERA_ENABLED:
|
|
return UsageEventType.CAMERA_ENABLED;
|
|
case UsageEventType.CAMERA_DISABLED:
|
|
return UsageEventType.CAMERA_DISABLED;
|
|
default:
|
|
return UsageEventType.TOOL_CALLED;
|
|
}
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
const body = (await request.json().catch(() => null)) as
|
|
| {
|
|
deviceUuid?: string;
|
|
eventType?: string;
|
|
detailJson?: string;
|
|
}
|
|
| null;
|
|
|
|
if (!body?.deviceUuid || typeof body.deviceUuid !== "string") {
|
|
return NextResponse.json(
|
|
{ error: "deviceUuid 是必填项。" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
if (!body.eventType || typeof body.eventType !== "string") {
|
|
return NextResponse.json(
|
|
{ error: "eventType 是必填项。" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
await requireDeviceAuth(request, body.deviceUuid);
|
|
await recordUsageEvent({
|
|
deviceUuid: body.deviceUuid,
|
|
eventType: toUsageEventType(body.eventType),
|
|
detailJson: typeof body.detailJson === "string" ? body.detailJson : undefined,
|
|
});
|
|
|
|
return NextResponse.json({ ok: true });
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{
|
|
error:
|
|
error instanceof Error ? error.message : "使用记录保存失败,请稍后再试。",
|
|
},
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
}
|