From d23413f287978bf3a3dba27b1d6b6b2ebd7b1dc3 Mon Sep 17 00:00:00 2001 From: Moe Date: Mon, 25 Jul 2022 12:16:37 -0700 Subject: [PATCH] Fix request for ShinobiHub Private config auto backup --- libs/shinobiHub.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/libs/shinobiHub.js b/libs/shinobiHub.js index 803248ac..b9914524 100644 --- a/libs/shinobiHub.js +++ b/libs/shinobiHub.js @@ -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})