Fix request for ShinobiHub Private config auto backup
parent
1750f79757
commit
d23413f287
|
|
@ -2,6 +2,9 @@ const fs = require('fs')
|
|||
const fetch = require('node-fetch')
|
||||
module.exports = function(s,config,lang,app,io){
|
||||
if(config.shinobiHubEndpoint === undefined){config.shinobiHubEndpoint = `https://hub.shinobi.video/`}else{config.shinobiHubEndpoint = s.checkCorrectPathEnding(config.shinobiHubEndpoint)}
|
||||
const {
|
||||
fetchWithAuthentication,
|
||||
} = require('./basic/utils.js')(process.cwd(),config)
|
||||
var stripUsernameAndPassword = function(string,username,password){
|
||||
if(username)string = string.split(username).join('_USERNAME_')
|
||||
if(password)string = string.split(password).join('_PASSWORD_')
|
||||
|
|
@ -53,20 +56,27 @@ module.exports = function(s,config,lang,app,io){
|
|||
json: JSON.stringify(monitorConfig)
|
||||
})
|
||||
if(validated.ok === true){
|
||||
request.post({
|
||||
url: `${config.shinobiHubEndpoint}api/${shinobiHubApiKey}/postConfiguration`,
|
||||
form: {
|
||||
"type": type,
|
||||
"brand": monitorConfig.ke,
|
||||
"name": monitorConfig.name,
|
||||
"description": "Backup at " + (new Date()),
|
||||
"json": validated.json,
|
||||
"details": JSON.stringify({
|
||||
// maybe ip address?
|
||||
})
|
||||
fetchWithAuthentication(
|
||||
`${config.shinobiHubEndpoint}api/${shinobiHubApiKey}/postConfiguration`,
|
||||
{
|
||||
method: 'POST',
|
||||
postData: {
|
||||
"type": type,
|
||||
"brand": monitorConfig.ke,
|
||||
"name": monitorConfig.name,
|
||||
"description": "Backup at " + (new Date()),
|
||||
"json": validated.json,
|
||||
"details": JSON.stringify({
|
||||
// maybe ip address?
|
||||
})
|
||||
}
|
||||
}
|
||||
}, function(err,httpResponse,body){
|
||||
callback(err,s.parseJSON(body) || {ok: false})
|
||||
).then(res => res.text())
|
||||
.then((data) => {
|
||||
callback(null,s.parseJSON(data) || {ok: false})
|
||||
})
|
||||
.catch((err) => {
|
||||
callback(err,{ok: false})
|
||||
})
|
||||
}else{
|
||||
callback(new Error(validated.msg),{ok: false})
|
||||
|
|
|
|||
Loading…
Reference in New Issue