From 00accc207da752a23513ef0dd5c9395a678de2f2 Mon Sep 17 00:00:00 2001 From: Matheus Sampaio Queiroga Date: Mon, 29 Aug 2022 23:28:00 +0000 Subject: [PATCH] Update client --- src/index.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index defbd4f..2dff557 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,11 +38,18 @@ export type home = { }; export const versionAPIs = ["https://mcpeversions.sirherobrine23.org", "https://mcpeversions_backup.sirherobrine23.org", "http://168.138.140.152"]; -export let versionUrl = versionAPIs[0]; -setInterval(async () => httpRequests.RAW_TEXT(versionAPIs[0]).then(() => versionAPIs[0]).catch(() => httpRequests.RAW_TEXT(versionAPIs[1]).then(() => versionAPIs[1])).catch(() => httpRequests.RAW_TEXT(versionAPIs[2]).then(() => versionAPIs[2])).then(ip => versionUrl).catch(() => console.warn("Cannot get Avaible API")), 1000*60*60*5); - export async function findVersion(bdsPlaform: BdsCorePlatforms, version?: string|boolean): Promise { - return httpRequests.getJson(`${versionUrl}/${bdsPlaform}/${typeof version === "undefined"?"":typeof version === "boolean"?"latest":"search?version="+version}`) + for (let url of versionAPIs) { + url += "/"+bdsPlaform; + if (typeof version !== "undefined") { + if (typeof version === "boolean"||version === "latest") url += "/latest"; + else url += `/search?version=${version}`; + } + const res = await httpRequests.fetchBuffer(url).catch(() => false); + if (res === false) continue; + return JSON.parse(res.toString("utf8"), (key, value) => key === "datePublish" ? new Date(value):value); + } + throw new Error("Failed to exec API request!"); } export const findBedrock = (version: string|boolean) => findVersion("bedrock", version).then((res: bedrock) => res);