'use strict'; const { Controller } = require('egg'); /** * web 用户端:边缘能力(`/api/web/edge/*`) * * 查询机先在本机局域网找"设备管理服务"(UDP 询问),找不到才来这里问云端。 * 云端把问题转给打包仓库那台扫码服务(它出站领任务、真拉一段录像确认)。 * * 这样查询机得到的结论和"本机自己校验"是同一套语义,不会各说一套。 */ class WebEdgeController extends Controller { /** * POST /api/web/edge/check { code } * * 返回 `data.state`: * - `ok` 设备确认过:`hasVideo` 为准 * - `no-plan` 这个运单在本主体下算不出回放计划(没绑工作台/摄像头) * - `no-device` 同主体没有在线的扫码服务,或它们都连不上该 NVR * - `no-credential` 录像机没有保存密码 * * `hasVideo` 三态:true / false / null(未知,调用方自己决定怎么展示) */ async check() { const { ctx } = this; const body = ctx.request.body || {}; const code = String(body.code || ctx.query.code || '').trim(); if (!code) ctx.throw(422, '缺少运单号'); const data = await ctx.service.edgeTask.checkVideo({ subjectId: ctx.state.subjectId, code, }); ctx.body = { ok: true, data }; } } module.exports = WebEdgeController;