diff --git a/libs/basic/utils.js b/libs/basic/utils.js index a8a162f2..8bbb9c0d 100644 --- a/libs/basic/utils.js +++ b/libs/basic/utils.js @@ -111,16 +111,18 @@ module.exports = (processCwd,config) => { let theRequester; const hasUsernameAndPassword = options.username && typeof options.password === 'string' const requestOptions = { - method : options.method || 'GET' + method : options.method || 'GET', + headers: {'Content-Type': 'application/json'} } if(typeof options.postData === 'object'){ - const formData = new FormData() - const formKeys = Object.keys(options.postData) - formKeys.forEach(function(key){ - const value = formKeys[key] - formData.set(key, value) - }) - requestOptions.body = formData + requestOptions.body = JSON.stringify(options.postData) + } else if(typeof options.postData === 'string'){ + try{ + JSON.parse(options.postData) + requestOptions.body = options.postData + }catch(err){ + + } } if(hasUsernameAndPassword && hasDigestAuthEnabled){ theRequester = (new DigestFetch(options.username, options.password)).fetch diff --git a/libs/control/ptz.js b/libs/control/ptz.js index 73578026..e73fad24 100644 --- a/libs/control/ptz.js +++ b/libs/control/ptz.js @@ -7,12 +7,12 @@ module.exports = function(s,config,lang){ const sliceUrlAuth = (url) => { return /^(.+?\/\/)(?:.+?:.+?@)?(.+)$/.exec(url).slice(1).join('') } - function getGenericControlParameters(options,urlType){ + function getGenericControlParameters(options,doStart){ const monitorConfig = s.group[options.ke].rawMonitorConfigurations[options.id] const controlUrlMethod = monitorConfig.details.control_url_method || 'GET' const controlBaseUrl = monitorConfig.details.control_base_url || s.buildMonitorUrl(monitorConfig, true) let theURL; - if(urlType === 'start'){ + if(doStart){ theURL = controlBaseUrl + monitorConfig.details[`control_url_${options.direction}`] }else{ theURL = controlBaseUrl + monitorConfig.details[`control_url_${options.direction}_stop`] @@ -42,7 +42,7 @@ module.exports = function(s,config,lang){ controlOptions, hasDigestAuthEnabled, requestUrl, - } = getGenericControlParameters(options,'start') + } = getGenericControlParameters(options,doStart) const response = { ok: true, type: lang[doStart ? 'Control Triggered' : 'Control Trigger Ended'] @@ -50,7 +50,7 @@ module.exports = function(s,config,lang){ const theRequest = fetchWithAuthentication(requestUrl,{ method: controlUrlMethod || controlOptions.method, digestAuth: hasDigestAuthEnabled, - body: controlOptions.postData || null + postData: controlOptions.postData || null }); theRequest.then(res => res.text()) .then((data) => { diff --git a/libs/shinobiHub.js b/libs/shinobiHub.js index b9914524..c067a4fc 100644 --- a/libs/shinobiHub.js +++ b/libs/shinobiHub.js @@ -66,9 +66,9 @@ module.exports = function(s,config,lang,app,io){ "name": monitorConfig.name, "description": "Backup at " + (new Date()), "json": validated.json, - "details": JSON.stringify({ + "details": { // maybe ip address? - }) + } } } ).then(res => res.text())