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", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@azure/storage-blob": "^12.6.0", "@azure/storage-blob": "^12.6.0",
"@the-bds-maneger/fetchsync": "github:The-Bds-Maneger/fetchSync",
"adm-zip": "^0.5.1", "adm-zip": "^0.5.1",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"cli-color": "^2.0.0", "cli-color": "^2.0.0",
@ -451,17 +450,6 @@
"node": ">=10" "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": { "node_modules/@types/cacheable-request": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",
@ -7489,13 +7477,6 @@
"defer-to-connect": "^2.0.0" "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": { "@types/cacheable-request": {
"version": "6.0.2", "version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",

View File

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

View File

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