mitchross-coral-installer-update
Moe Alam 2021-01-18 19:23:57 -08:00
commit 59b810fac6
3 changed files with 38 additions and 16 deletions

View File

@ -63,4 +63,14 @@ module.exports = {
})
return newObject
},
createQueryStringFromObject: (theObject) => {
const string = []
const keys = Object.keys(theObject)
keys.forEach((key) => {
const value = theObject[key]
if(value)string.push(`${key}=${value}`)
})
return string.join('&')
}
}

View File

@ -220,13 +220,18 @@ module.exports = function(s,config,lang){
let stopURL = controlBaseUrl + monitorConfig.details[`control_url_${options.direction}_stop`]
let controlOptions = s.cameraControlOptionsFromUrl(stopURL,monitorConfig)
let requestOptions = {
url : stopURL,
method : controlOptions.method,
auth : {
user : controlOptions.username,
pass : controlOptions.password
url : controlBaseUrl + controlOptions.path,
method : controlOptions.method
}
if(controlOptions.username && controlOptions.password){
requestOptions.auth = {
user: controlOptions.username,
pass: controlOptions.password
}
}
if(controlOptions.postData){
requestOptions.form = controlOptions.postData
}
if(monitorConfig.details.control_digest_auth === '1'){
requestOptions.uri = sliceUrlAuth(requestOptions.url);
delete requestOptions.url;
@ -253,13 +258,18 @@ module.exports = function(s,config,lang){
let controlURL = controlBaseUrl + monitorConfig.details[`control_url_${options.direction}`]
let controlOptions = s.cameraControlOptionsFromUrl(controlURL,monitorConfig)
let requestOptions = {
url: controlURL,
method: controlOptions.method,
auth: {
url: controlBaseUrl + controlOptions.path,
method: controlOptions.method
}
if(controlOptions.username && controlOptions.password){
requestOptions.auth = {
user: controlOptions.username,
pass: controlOptions.password
}
}
if(controlOptions.postData){
requestOptions.form = controlOptions.postData
}
if(monitorConfig.details.control_digest_auth === '1'){
requestOptions.uri = sliceUrlAuth(requestOptions.url);
delete requestOptions.url;

View File

@ -10,7 +10,7 @@ const connectionTester = require('connection-tester')
const SoundDetection = require('shinobi-sound-detection')
const async = require("async");
const URL = require('url')
const { copyObject, createQueue, queryStringToObject } = require('./common.js')
const { copyObject, createQueue, queryStringToObject, createQueryStringFromObject } = require('./common.js')
module.exports = function(s,config,lang){
const {
probeMonitor,
@ -447,15 +447,17 @@ module.exports = function(s,config,lang){
}else if(!URLobject.port){
URLobject.port = 80
}
options = {
const options = {
host: URLobject.hostname,
port: URLobject.port,
method: monitorConfig.details.control_url_method,
path: URLobject.pathname,
query: queryStringToObject(URLobject.query || ""),
};
if(URLobject.query){
options.path=options.path+'?'+URLobject.query
method: monitorConfig.details.control_url_method
}
const queryStringObjects = queryStringToObject(URLobject.query || "")
if (queryStringObjects && queryStringObjects.postData) {
options.postData = decodeURIComponent(queryStringObjects.postData)
options.path = URLobject.pathname + '?' + decodeURIComponent(createQueryStringFromObject(Object.assign(queryStringObjects,{postData: null})))
} else {
options.path = URLobject.pathname
}
if(URLobject.username&&URLobject.password){
options.username = URLobject.username