Fix request for ShinobiHub Private config auto backup

ejs-templating-update
Moe 2022-07-25 12:16:37 -07:00
parent 1750f79757
commit d23413f287
1 changed files with 23 additions and 13 deletions

View File

@ -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})