Async functions #172

Merged
Sirherobrine23 merged 7 commits from AsyncFunctions into main 2021-08-27 21:49:53 +00:00
3 changed files with 32 additions and 47 deletions

19
package-lock.json generated
View File

@ -10,7 +10,6 @@
"license": "AGPL-3.0-or-later",
"dependencies": {
"@azure/storage-blob": "^12.6.0",
"@the-bds-maneger/fetchsync": "github:The-Bds-Maneger/fetchSync",
"adm-zip": "^0.5.1",
"body-parser": "^1.19.0",
"cli-color": "^2.0.0",
@ -451,17 +450,6 @@
"node": ">=10"
}
},
"node_modules/@the-bds-maneger/fetchsync": {
"version": "1.0.0",
"resolved": "git+ssh://git@github.com/The-Bds-Maneger/fetchSync.git#c4af0cae45f434250dd7d2b0617395b5001371df",
"license": "AGPL-3.0-or-later",
"dependencies": {
"node-fetch": "^2.6.1"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@types/cacheable-request": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",
@ -7489,13 +7477,6 @@
"defer-to-connect": "^2.0.0"
}
},
"@the-bds-maneger/fetchsync": {
"version": "git+ssh://git@github.com/The-Bds-Maneger/fetchSync.git#c4af0cae45f434250dd7d2b0617395b5001371df",
"from": "@the-bds-maneger/fetchsync@github:The-Bds-Maneger/fetchSync",
"requires": {
"node-fetch": "^2.6.1"
}
},
"@types/cacheable-request": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",

View File

@ -54,7 +54,6 @@
},
"dependencies": {
"@azure/storage-blob": "^12.6.0",
"@the-bds-maneger/fetchsync": "github:The-Bds-Maneger/fetchSync",
"adm-zip": "^0.5.1",
"body-parser": "^1.19.0",
"cli-color": "^2.0.0",

View File

@ -1,12 +1,19 @@
// External User ip
const fetchSync = require("@the-bds-maneger/fetchsync");
const Request = require("../lib/Requests");
const os = require("os");
const { GetTempHost } = require("../lib/BdsSettings");
const externalIP = {
ipv4: fetchSync("https://api.ipify.org/").text().replace("\n", ""),
ipv6: fetchSync("https://api64.ipify.org/").text().replace("\n", "")
}
Request.TEXT("https://api.ipify.org").then(external_ipv4 => {
Request.TEXT("https://api64.ipify.org/").then(external_ipv6 => {
const externalIP = {
ipv4: external_ipv4.replace("\n", ""),
ipv6: external_ipv6.replace("\n", "")
}
module.exports.externalIP = externalIP;
module.exports.ip = externalIP;
});
});
// Internal ip user
const interfaces = os.networkInterfaces();
@ -48,7 +55,7 @@ var host = null,
if (GetTempHost()){
// Get HOST
HostResponse = fetchSync("https://bds-core-back-end.vercel.app/Gethost", {
Request.JSON("https://bds-core-back-end.vercel.app/Gethost", {
method: "POST",
mode: "cors",
body: JSON.stringify({
@ -58,15 +65,13 @@ if (GetTempHost()){
headers: {
"Content-Type": "application/json"
}
}).json();
}).then(HostResponse => {
global.BdsTempHost = HostResponse.user.host.host
host = HostResponse.user.host.host
console.log(`Bds Maneger Core Temp Host ID: ${HostResponse.user.ID}`)
// Delete Host
process.on("exit", function () {
const deleted_host = fetchSync("https://bds-core-back-end.vercel.app/DeleteHost", {
Request.JSON("https://bds-core-back-end.vercel.app/DeleteHost", {
method: "post",
body: JSON.stringify({
"ID": HostResponse.user.ID
@ -74,14 +79,14 @@ if (GetTempHost()){
headers: {
"Content-Type": "application/json"
}
}).json()
}).then(deleted_host => {
if (deleted_host.error) console.log(deleted_host.error)
})
});
});
});
} else module.exports.host = null
module.exports = {
externalIP,
ip: externalIP,
internal_ip,
Interfaces,
HostResponse,