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

Commit 00accc2

Browse files
Update client
1 parent 67ddb32 commit 00accc2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,18 @@ export type home = {
3838
};
3939

4040
export const versionAPIs = ["https://mcpeversions.sirherobrine23.org", "https://mcpeversions_backup.sirherobrine23.org", "http://168.138.140.152"];
41-
export let versionUrl = versionAPIs[0];
42-
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);
43-
4441
export async function findVersion(bdsPlaform: BdsCorePlatforms, version?: string|boolean): Promise<bedrock|bedrock[]|java|java[]|pocketmine|pocketmine[]|spigot|spigot[]> {
45-
return httpRequests.getJson(`${versionUrl}/${bdsPlaform}/${typeof version === "undefined"?"":typeof version === "boolean"?"latest":"search?version="+version}`)
42+
for (let url of versionAPIs) {
43+
url += "/"+bdsPlaform;
44+
if (typeof version !== "undefined") {
45+
if (typeof version === "boolean"||version === "latest") url += "/latest";
46+
else url += `/search?version=${version}`;
47+
}
48+
const res = await httpRequests.fetchBuffer(url).catch(() => false);
49+
if (res === false) continue;
50+
return JSON.parse(res.toString("utf8"), (key, value) => key === "datePublish" ? new Date(value):value);
51+
}
52+
throw new Error("Failed to exec API request!");
4653
}
4754

4855
export const findBedrock = (version: string|boolean) => findVersion("bedrock", version).then((res: bedrock) => res);

0 commit comments

Comments
 (0)