Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
Add raw_request in Return Object
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirherobrine23 committed Jan 1, 2022
1 parent 915af11 commit 41efcb5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
63 changes: 31 additions & 32 deletions src/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 41efcb5

Please sign in to comment.