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

Commit

Permalink
Update client
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirherobrine23 authored Sep 21, 2022
1 parent fcca211 commit 809a72d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ Use the following API to fetch versions:
Example to latest bedrock: `curl -s https://mcpeversions.sirherobrine23.org/bedrock/latest` or search version: `curl -s https://mcpeversions.sirherobrine23.org/bedrock/search?version=1.18.1.02`

> Avaible to `/bedrock`, `/java`, `/pocketmine`, `/spigot`, `/paper` and `/powernukkit`.
### Static files

I'm releasing a static version of the versions to solve some problems.

> example:
> `https://mcpeversion-static.sirherobrine23.org/{platform}/{version}.json`.
>
> `curl -s https://mcpeversion-static.sirherobrine23.org/bedrock/latest.json`.
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { paperSchema } from "./db/paper";
import type { powernukkitSchema } from "./db/powernukkit";
import type { pocketminemmpSchema } from "./db/pocketmine";
import type { spigotSchema } from "./db/spigot";
export const versionURLs = ["https://mcpeversions.sirherobrine23.org", "https://mcpeversions_backup.sirherobrine23.org", "http://168.138.140.152"];
export const versionURLs = ["https://mcpeversion-static.sirherobrine23.org/", "https://mcpeversions.sirherobrine23.org", "https://mcpeversions_backup.sirherobrine23.org"];

export type BdsCorePlatforms = "bedrock"|"java"|"paper"|"powernukkit"|"pocketmine"|"spigot";
export type all = bedrockSchema|javaSchema|powernukkitSchema|paperSchema|pocketminemmpSchema|spigotSchema
Expand All @@ -23,9 +23,16 @@ export async function findVersion<PlatformSchema = all>(bdsPlaform: BdsCorePlatf
export async function findVersion<PlatformSchema = all|all[]>(bdsPlaform: BdsCorePlatforms, version?: string|boolean): Promise<PlatformSchema> {
for (let url of versionURLs) {
url += "/"+bdsPlaform;
if (typeof version !== "undefined") {
if (typeof version === "boolean"||version === "latest") url += "/latest";
else url += `/search?version=${version}`;
if (/static/.test(url)) {
if (version === undefined) url += "/all.json";
else if (typeof version === "boolean") url += "/latest.json";
else url += `/${version}.json`;

} else {
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;
Expand Down
6 changes: 6 additions & 0 deletions static_version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,47 @@ if (!fsOld.existsSync(Paper)) await fs.mkdir(Paper, {recursive: true});

const bedrockData = await (await fetch("https://mcpeversions.sirherobrine23.org/bedrock")).json();
fs.writeFile(path.join(Bedrock, "latest.json"), JSON.stringify(bedrockData.find(release => release.latest), null, 2));
fs.writeFile(path.join(Bedrock, "all.json"), JSON.stringify(bedrockData, null, 2));
await Promise.all(bedrockData.map(releases => {
const version = path.join(Bedrock, `${releases.version}.json`);
return fs.writeFile(version, JSON.stringify(releases, null, 2));
}));

const PocketmineData = await (await fetch("https://mcpeversions.sirherobrine23.org/Pocketmine")).json();
fs.writeFile(path.join(Pocketmine, "latest.json"), JSON.stringify(PocketmineData.find(release => release.latest), null, 2));
fs.writeFile(path.join(Pocketmine, "all.json"), JSON.stringify(PocketmineData, null, 2));
await Promise.all(PocketmineData.map(releases => {
const version = path.join(Pocketmine, `${releases.version}.json`);
return fs.writeFile(version, JSON.stringify(releases, null, 2));
}));

const PowernukkitData = await (await fetch("https://mcpeversions.sirherobrine23.org/Powernukkit")).json();
fs.writeFile(path.join(Powernukkit, "latest.json"), JSON.stringify(PowernukkitData.find(release => release.latest), null, 2));
fs.writeFile(path.join(Powernukkit, "all.json"), JSON.stringify(PowernukkitData, null, 2));
await Promise.all(PowernukkitData.map(releases => {
const version = path.join(Powernukkit, `${releases.version}.json`);
return fs.writeFile(version, JSON.stringify(releases, null, 2));
}));

const JavaData = await (await fetch("https://mcpeversions.sirherobrine23.org/Java")).json();
fs.writeFile(path.join(Java, "latest.json"), JSON.stringify(JavaData.find(release => release.latest), null, 2));
fs.writeFile(path.join(Java, "all.json"), JSON.stringify(JavaData, null, 2));
await Promise.all(JavaData.map(releases => {
const version = path.join(Java, `${releases.version}.json`);
return fs.writeFile(version, JSON.stringify(releases, null, 2));
}));

const SpigotData = await (await fetch("https://mcpeversions.sirherobrine23.org/Spigot")).json();
fs.writeFile(path.join(Spigot, "latest.json"), JSON.stringify(SpigotData.find(release => release.latest), null, 2));
fs.writeFile(path.join(Spigot, "all.json"), JSON.stringify(SpigotData, null, 2));
await Promise.all(SpigotData.map(releases => {
const version = path.join(Spigot, `${releases.version}.json`);
return fs.writeFile(version, JSON.stringify(releases, null, 2));
}));

const PaperData = await (await fetch("https://mcpeversions.sirherobrine23.org/Paper")).json();
fs.writeFile(path.join(Paper, "latest.json"), JSON.stringify(PaperData.find(release => release.latest), null, 2));
fs.writeFile(path.join(Paper, "all.json"), JSON.stringify(PaperData, null, 2));
await Promise.all(PaperData.map(releases => {
const version = path.join(Paper, `${releases.version}_${releases.build}.json`);
return fs.writeFile(version, JSON.stringify(releases, null, 2));
Expand Down

0 comments on commit 809a72d

Please sign in to comment.