From 82eb83df71b6101285843cb89abb38af81851272 Mon Sep 17 00:00:00 2001 From: Moe Date: Sun, 19 Dec 2021 12:32:44 -0800 Subject: [PATCH] fix onvif scanner result draw --- libs/common.js | 12 ++++++++++++ libs/scanners/utils.js | 22 +++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/libs/common.js b/libs/common.js index a993e20c..f50e6b4c 100644 --- a/libs/common.js +++ b/libs/common.js @@ -1,4 +1,5 @@ const async = require("async"); +const fetch = require("node-fetch"); const mergeDeep = function(...objects) { const isObject = obj => obj && typeof obj === 'object'; @@ -21,7 +22,18 @@ const mergeDeep = function(...objects) { return prev; }, {}); } +const getBuffer = async (url) => { + try { + const response = await fetch(url); + const arrayBuffer = await response.arrayBuffer(); + const buffer = Buffer.from(arrayBuffer); + return buffer; + } catch (error) { + return { error }; + } +}; module.exports = { + getBuffer: getBuffer, mergeDeep: mergeDeep, validateIntValue: (value) => { const newValue = !isNaN(parseInt(value)) ? parseInt(value) : null diff --git a/libs/scanners/utils.js b/libs/scanners/utils.js index 0a10107f..f13935ae 100644 --- a/libs/scanners/utils.js +++ b/libs/scanners/utils.js @@ -2,6 +2,7 @@ var os = require('os'); const onvif = require("shinobi-onvif"); const { stringContains, + getBuffer, } = require('../common.js') module.exports = (s,config,lang) => { const ipRange = (start_ip, end_ip) => { @@ -119,9 +120,7 @@ module.exports = (s,config,lang) => { ProfileToken : device.current_profile.token, Protocol : 'RTSP' }) - const snapUri = (await device.services.media.getSnapshotUri({ - ProfileToken : device.current_profile.token, - })).GetSnapshotUriResponse.MediaUri.Uri + var cameraResponse = { ip: camera.ip, port: camera.port, @@ -145,16 +144,13 @@ module.exports = (s,config,lang) => { } responseList.push(cameraResponse) var imageSnap - if(cameraResponse.uri){ - try{ - imageSnap = (await s.getSnapshotFromOnvif({ - username: onvifUsername, - password: onvifPassword, - uri: snapUri, - })).toString('base64'); - }catch(err){ - s.debugLog(err) - } + try{ + const snapUri = (await device.services.media.getSnapshotUri({ + ProfileToken : device.current_profile.token, + })).data.GetSnapshotUriResponse.MediaUri.Uri + imageSnap = (await getBuffer(snapUri)).toString('base64'); + }catch(err){ + s.debugLog(err) } if(foundCameraCallback)foundCameraCallback(Object.assign(cameraResponse,{f: 'onvif', snapShot: imageSnap})) }catch(err){