Remove sync-fetch

This commit is contained in:
2021-05-19 21:17:55 -03:00
parent 9eee188727
commit 072e83c463
5 changed files with 48 additions and 30 deletions

43
fetchSync.js Normal file

@ -0,0 +1,43 @@
const { execSync } = require("child_process");
const { tmpdir } = require("os");
const ce = require("./commandExist");
/**
* make a request and receive its value, this locks up all the java work
*
* @param {string} url
* @param {JSON} options
* @return {*}
*/
const FetchSync = function (url, options){
url = decodeURI(url);
var command = {
command: null,
shell: null
};
if (typeof options !== "object") options = {}
if (process.platform === "linux" || process.platform === "android" || process.platform === "darwin"){
if (ce("curl")) {
command.command = `curl -sS "${url}"`
command.shell = "/bin/sh"
} else if (ce("wget")) {
command.command = `wget -qO- "${url}"`
command.shell = "/bin/sh"
}
} else if (process.platform === "win32") {
if (ce("curl")) {
command.command = `curl -sS "${url}"`
command.shell = "C:\\Windows\\System32\\cmd.exe"
} else {
command.command = `(Invoke-WebRequest -URI "${url}").Content`;
if (process.arch === "x64") command.shell = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe";
else command.shell = "C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe";
}
}
const ValueReturn = execSync(command.command.split(/\s+/).join(" "), {cwd: tmpdir(), shell: command.shell})
return {
text: function (){return ValueReturn.toString()},
json: function(){return JSON.parse(ValueReturn.toString())}
}
}
module.exports = FetchSync

@ -3,13 +3,13 @@ const { resolve, join } = require("path");
const { CronJob } = require("cron");
const path = require("path")
const fs = require("fs");
const { getConfigHome } = require("./GetPlatformFolder")
const { getConfigHome } = require("./GetPlatformFolder");
const commandExistsSync = require("./commandExist");
const FetchSync = require("sync-fetch")
module.exports = require("./bdsgetPaths");
const FetchSync = require("./fetchSync")
const bds_core_package = join(__dirname, "package.json")
const bds_maneger_version = require(bds_core_package).version
module.exports = require("./bdsgetPaths");
if (process.env.SHOW_BDS_VERSION !== undefined) console.log(`Running the Bds Maneger API in version ${bds_maneger_version}`)
function date(format) {
const today = new Date(),

23
package-lock.json generated

@ -7,7 +7,6 @@
"": {
"name": "@the-bds-maneger/core",
"version": "1.9.16",
"hasInstallScript": true,
"license": "AGPL-3.0-or-later",
"dependencies": {
"adm-zip": "^0.5.1",
@ -30,7 +29,6 @@
"qrcode": "^1.4.4",
"request-ip": "^2.1.3",
"shelljs": "^0.8.4",
"sync-fetch": "^0.3.0",
"telegraf": "^4.0.0"
},
"bin": {
@ -2473,18 +2471,6 @@
"node": ">=8"
}
},
"node_modules/sync-fetch": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/sync-fetch/-/sync-fetch-0.3.0.tgz",
"integrity": "sha512-dJp4qg+x4JwSEW1HibAuMi0IIrBI3wuQr2GimmqB7OXR50wmwzfdusG+p39R9w3R6aFtZ2mzvxvWKQ3Bd/vx3g==",
"dependencies": {
"buffer": "^5.7.0",
"node-fetch": "^2.6.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/table": {
"version": "6.6.0",
"resolved": "https://registry.npmjs.org/table/-/table-6.6.0.tgz",
@ -4716,15 +4702,6 @@
"has-flag": "^4.0.0"
}
},
"sync-fetch": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/sync-fetch/-/sync-fetch-0.3.0.tgz",
"integrity": "sha512-dJp4qg+x4JwSEW1HibAuMi0IIrBI3wuQr2GimmqB7OXR50wmwzfdusG+p39R9w3R6aFtZ2mzvxvWKQ3Bd/vx3g==",
"requires": {
"buffer": "^5.7.0",
"node-fetch": "^2.6.1"
}
},
"table": {
"version": "6.6.0",
"resolved": "https://registry.npmjs.org/table/-/table-6.6.0.tgz",

@ -7,7 +7,6 @@
"description": "Scripts to manage minecraft server's",
"private": false,
"main": "index.js",
"scripts": {
"start": "node bin/bds_maneger.js -s",
"stop": "node -p 'if (require(\"./\").kill()) console.log(\"Killeds\");else console.log(\"Not runs\");'",
@ -66,7 +65,6 @@
"qrcode": "^1.4.4",
"request-ip": "^2.1.3",
"shelljs": "^0.8.4",
"sync-fetch": "^0.3.0",
"telegraf": "^4.0.0"
},
"devDependencies": {

@ -1,5 +1,5 @@
const fetchSync = require("sync-fetch");
module.exports.external_ip = module.exports.ip = fetchSync("https://ipecho.net/plain").text()
const FetchSync = require("../fetchSync");
module.exports.external_ip = module.exports.ip = FetchSync("https://ipecho.net/plain").text()
const interfaces = require("os").networkInterfaces();
const internal_ip = []