From 41efcb5afcc75bd0c4fb6041ed9591948b04b8df Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Fri, 31 Dec 2021 22:29:50 -0300 Subject: [PATCH] Add raw_request in Return Object --- package.json | 2 +- src/cjs/index.js | 63 ++++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 0d54bb5..ce0c008 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@the-bds-maneger/server_versions", - "version": "1.0.0", + "version": "1.0.1", "description": "Auto Find Minecraft Server Versions", "main": "src/cjs/index.js", "publishConfig": { diff --git a/src/cjs/index.js b/src/cjs/index.js index 60f5163..cc8de1f 100644 --- a/src/cjs/index.js +++ b/src/cjs/index.js @@ -14,46 +14,45 @@ const GithubRawUrl = `https://raw.githubusercontent.com/The-Bds-Maneger/ServerVe const Mod = {}; function MainFunctionFind(ServerVersion = "latest", ServerPlatform = "bedrock", VersionsList = require("../Versions.json")) { + if (typeof ServerPlatform !== "string") throw new Error("ServerPlatform must be a string"); + + if (typeof ServerVersion !== "string") throw new Error("ServerVersion must be a string"); + ServerVersion = ServerVersion.toLowerCase(); ServerPlatform = ServerPlatform.toLowerCase(); + if (ServerVersion === "latest") { + ServerVersion = VersionsList.latest[ServerPlatform]; + } + // + // ------------------------------------------------------------------------------------------------------------ + // Script + // + const PlatformFilted = VersionsList.platform.filter(SV => SV.name === ServerPlatform); + if (PlatformFilted.length === 0) throw new Error(`Platform ${ServerPlatform} not found`); + const VersionFiltred = PlatformFilted.filter(SV => SV.version === ServerVersion)[0]; + if (VersionFiltred === undefined) throw new Error("Version not found"); const DataReturn = { url: "", version: "", - Date: new Date() + Date: new Date(), + raw_request: VersionFiltred } - if (typeof ServerPlatform !== "string") throw new Error("ServerPlatform must be a string"); - - if (typeof ServerVersion === "string") { - ServerVersion = ServerVersion.toLowerCase(); ServerPlatform = ServerPlatform.toLowerCase(); - if (ServerVersion === "latest") { - ServerVersion = VersionsList.latest[ServerPlatform]; - } - // - // ------------------------------------------------------------------------------------------------------------ - // Script - // - const PlatformFilted = VersionsList.platform.filter(SV => SV.name === ServerPlatform); - if (PlatformFilted.length === 0) throw new Error(`Platform ${ServerPlatform} not found`); - const VersionFiltred = PlatformFilted.filter(SV => SV.version === ServerVersion)[0]; - if (VersionFiltred === undefined) throw new Error("Version not found"); - DataReturn.raw_request = VersionFiltred; - if (typeof VersionFiltred.data === "string") { - DataReturn.url = VersionFiltred.data; + if (typeof VersionFiltred.data === "string") { + DataReturn.url = VersionFiltred.data; + DataReturn.version = VersionFiltred.version; + DataReturn.Date = new Date(VersionFiltred.Date); + } else if (typeof VersionFiltred.data[process.platform] === "object") { + if (typeof VersionFiltred.data[process.platform][process.arch] === "string") { + DataReturn.url = VersionFiltred.data[process.platform][process.arch]; DataReturn.version = VersionFiltred.version; DataReturn.Date = new Date(VersionFiltred.Date); - } else if (typeof VersionFiltred.data[process.platform] === "object") { - if (typeof VersionFiltred.data[process.platform][process.arch] === "string") { - DataReturn.url = VersionFiltred.data[process.platform][process.arch]; - DataReturn.version = VersionFiltred.version; - DataReturn.Date = new Date(VersionFiltred.Date); - } else { - const ArchFiltred = Object.keys(VersionFiltred.data[process.platform]).filter(Arch => !Arch); - throw new Error(`Architecture ${ArchFiltred} not found`); - } } else { - const Err = new Error("Error getting the version"); - Err.Error_raw = VersionFiltred; - throw Err; + const ArchFiltred = Object.keys(VersionFiltred.data[process.platform]).filter(Arch => !Arch); + throw new Error(`Architecture ${ArchFiltred} not found`); } - } else throw new Error("ServerVersion must be a string"); + } else { + const Err = new Error("Error getting the version"); + Err.Error_raw = VersionFiltred; + throw Err; + } return DataReturn; }