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.
110 lines
3.6 KiB
110 lines
3.6 KiB
'use strict';
|
|
const moment = require('moment')
|
|
const request = require('superagent')
|
|
|
|
function videoList (opts) {
|
|
return async function (ctx) {
|
|
try {
|
|
const { models, } = ctx.fs.dc;
|
|
const { app, yingshiTokenRes } = ctx
|
|
|
|
let yingshiToken = ''
|
|
if (yingshiTokenRes && yingshiTokenRes.token && yingshiTokenRes.expire && moment().isBefore(moment(yingshiTokenRes.expire))) {
|
|
yingshiToken = yingshiTokenRes.token
|
|
} else {
|
|
const tokenRes = await app.fs.yingshiRequest.post(`lapp/token/get`, {
|
|
query: {
|
|
appKey: opts.yingshiKey,
|
|
appSecret: opts.yingshiSecret
|
|
}
|
|
})
|
|
if (tokenRes.code == 200 && tokenRes.data) {
|
|
const { accessToken, expireTime } = tokenRes.data
|
|
|
|
ctx.yingshiTokenRes = {
|
|
token: accessToken,
|
|
expire: expireTime
|
|
}
|
|
yingshiToken = accessToken
|
|
} else {
|
|
throw '未能获取进行萤石鉴权'
|
|
}
|
|
}
|
|
|
|
// const deviceRes = await app.fs.yingshiRequest.post(`lapp/device/list`, {
|
|
// query: {
|
|
// accessToken: yingshiToken,
|
|
// }
|
|
// })
|
|
|
|
ctx.status = 200;
|
|
|
|
let deviceRes_ = [{
|
|
deviceName: '楼前大桥',
|
|
deviceSerial: 'L48947105',
|
|
}, {
|
|
deviceName: '滁北大桥',
|
|
deviceSerial: 'L48947108',
|
|
}, {
|
|
deviceName: '新联桥',
|
|
deviceSerial: 'L48947110',
|
|
}, {
|
|
deviceName: '湾庄线',
|
|
deviceSerial: 'L48947112',
|
|
}, {
|
|
deviceName: '新土线',
|
|
deviceSerial: 'AA9943808',
|
|
}, {
|
|
deviceName: '东文大桥',
|
|
deviceSerial: 'L48947087',
|
|
}, {
|
|
deviceName: '莲姚线',
|
|
deviceSerial: 'L48947082',
|
|
}, {
|
|
deviceName: '荷漳公路',
|
|
deviceSerial: 'L48947109',
|
|
}, {
|
|
deviceName: '新武大桥',
|
|
deviceSerial: 'L48947086',
|
|
},]
|
|
|
|
const deviceState = await Promise.all(deviceRes_.map(d => {
|
|
return app.fs.yingshiRequest.post(`lapp/device/info`, {
|
|
query: {
|
|
accessToken: yingshiToken,
|
|
deviceSerial: d.deviceSerial
|
|
}
|
|
})
|
|
}))
|
|
|
|
for (let d of deviceRes_) {
|
|
let corState = deviceState.find(item => item.code == 200 && item.data && item.data.deviceSerial == d.deviceSerial)
|
|
if (corState) {
|
|
d.status = corState.data.status
|
|
} else {
|
|
d.status = 0
|
|
}
|
|
d.token = yingshiToken
|
|
}
|
|
|
|
ctx.body = deviceRes_
|
|
// ||
|
|
// (deviceRes.data || []).map(item => {
|
|
// return {
|
|
// ...item,
|
|
// token: yingshiToken,
|
|
// }
|
|
// })
|
|
} catch (error) {
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
|
|
ctx.status = 400;
|
|
ctx.body = {
|
|
message: typeof error == 'string' ? error : undefined
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
videoList
|
|
};
|