You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.6 KiB

3 years ago
'use strict';
3 years ago
const moment = require('moment')
3 years ago
async function createYingshi (ctx) {
let errMsg = '添加萤石摄像头失败'
3 years ago
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
const { utils: { token4yingshi } } = ctx.app.fs
3 years ago
3 years ago
const {
id, name, cloudControl, highDefinition, memoryCard,
voice, kindId, abilityId, rtmp, serialNo, longitude, latitude,
} = ctx.request.body;
const serialNo_ = String(serialNo).toUpperCase()
const secretRes = await models.SecretYingshi.findAll()
3 years ago
let cameraBeloneSecretId = 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
}
}
3 years ago
if (!cameraBeloneSecretId) {
errMsg = '请联系管理员核验或新增萤石云权限'
throw errMsg
}
3 years ago
let storageData = {
type: 'yingshi', name, cloudControl, highDefinition, memoryCard,
voice, longitude, latitude, kindId, abilityId, rtmp,
3 years ago
yingshiSecretId: cameraBeloneSecretId
3 years ago
}
if (id) {
await models.Camera.update(storageData, {
where: {
id,
}
})
} else {
3 years ago
storageData.createTime = moment().format()
storageData.createUserId = userId
storageData.forbidden = false
3 years ago
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
}
3 years ago
}
}
3 years ago
async function getNvrSteam (ctx) {
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
ctx.status = 200;
ctx.body = {}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
async function createNvrCamera (ctx) {
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
ctx.status = 200;
ctx.body = {}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
async function createIpcCamera (ctx) {
try {
const { models } = ctx.fs.dc
const { userId, token } = ctx.fs.api
const { utils: { token4yingshi } } = ctx.app.fs
const {
id, name, cloudControl, memoryCard,
voice, longitude, latitude, rtmp,
serialNo, kindId, abilityId,
} = ctx.request.body;
let storageData = {
type: 'ipc', name, cloudControl, memoryCard,
voice, longitude, latitude, rtmp,
serialNo, kindId, abilityId,
}
if (id) {
await models.Camera.update(storageData, {
where: {
id,
}
})
} else {
storageData.createTime = moment().format()
storageData.createUserId = userId
storageData.forbidden = false
await models.Camera.create(storageData)
}
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {}
}
}
3 years ago
module.exports = {
3 years ago
createYingshi,
getNvrSteam,
createNvrCamera,
createIpcCamera,
3 years ago
};