'use strict'; async function createYingshi (ctx) { let errMsg = '添加萤石摄像头失败' try { const { models } = ctx.fs.dc const { userId, token } = ctx.fs.api const { utils: { token4yingshi } } = ctx.app.fs const { id, name, cloudControl, highDefinition, memoryCard, voice, kindId, abilityId, rtmp, serialNo } = ctx.request.body; const serialNo_ = String(serialNo).toUpperCase() const secretRes = await models.SecretYingshi.findAll() let cameraBeloneSecret = null for (let s of secretRes) { const tokenYingshi = await token4yingshi(s.dataValues) // 检测设备所属 const cameraState = await ctx.app.fs.yingshiRequest.post('lapp/device/info', { query: { accessToken: tokenYingshi, deviceSerial: serialNo_ } }) if (cameraState.code == 200) { cameraBeloneSecretId = s.dataValues.id break } } if (!cameraBeloneSecret) { errMsg = '请联系管理员核验或新增萤石云权限' throw errMsg } let storageData = { type: 'yingshi', name, cloudControl, highDefinition, memoryCard, voice, longitude, latitude, kindId, abilityId, rtmp, } if (id) { storageData.createTime = moment().format() storageData.createUserId = userId await models.Camera.update(storageData, { where: { id, } }) } else { await models.Camera.create(storageData) } ctx.status = 204; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: errMsg } } } module.exports = { createYingshi };