Fixing sending postData with control URLs. Fixed non-working stop command for PTZ control.
parent
e5569f4b44
commit
e332929fd0
|
@ -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
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue