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

Commit

Permalink
re-added system and arch rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirherobrine23 committed May 3, 2022
1 parent ba3364c commit 0ffc342
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export default findUrlVersion;
*
* @param server - Bds Core Platform.
* @param Version - Version of server, any type of boolean to get latest version or `latest` to get latest version.
* @param Arch - Architecture of server.
* @param Os - Operating system of server.
* @returns Server Platform with url to download and date published.
*/
export async function findUrlVersion(server: BdsCorePlatforms, Version: string|boolean): Promise<{version: string; url: string; datePublish: Date; raw?: Root["versions"]["bedrock"][0]|Root["versions"]["java"][0]|Root["versions"]["pocketmine"][0]|Root["versions"]["spigot"][0]}> {
export async function findUrlVersion(server: BdsCorePlatforms, Version: string|boolean, Arch?: string, Os?: string): Promise<{version: string; url: string; datePublish: Date; raw?: Root["versions"]["bedrock"][0]|Root["versions"]["java"][0]|Root["versions"]["pocketmine"][0]|Root["versions"]["spigot"][0]}> {
if (server === "bedrock") {
let bedrockData: Root["versions"]["bedrock"][0] = undefined;
if (Version === "latest"||typeof Version === "boolean") {
Expand All @@ -23,7 +25,7 @@ export async function findUrlVersion(server: BdsCorePlatforms, Version: string|b
if (!bedrockData) throw new Error("No version found");
return {
version: bedrockData.version,
url: bedrockData[process.platform][process.arch],
url: bedrockData[Os?Os:process.platform][Arch?Arch:process.arch],
datePublish: new Date(bedrockData.datePublish),
raw: bedrockData
};
Expand Down Expand Up @@ -78,10 +80,12 @@ export async function findUrlVersion(server: BdsCorePlatforms, Version: string|b
*
* @param server - Bds Core Platform.
* @param Version - Version of server, any type of boolean to get latest version or `latest` to get latest version.
* @param Arch - Architecture of server.
* @param Os - Operating system of server.
* @returns Object with the publication date and the file's Buffer.
*/
export async function getBuffer(server: BdsCorePlatforms, Version: string|boolean): Promise<{datePublish: Date; dataBuffer: Buffer;}> {
const {datePublish, url} = await findUrlVersion(server, Version);
export async function getBuffer(server: BdsCorePlatforms, Version: string|boolean, Arch?: string, Os?: string): Promise<{datePublish: Date; dataBuffer: Buffer;}> {
const {datePublish, url} = await findUrlVersion(server, Version, Arch, Os);
return {
datePublish: datePublish,
dataBuffer: await fetchBuffer(url)
Expand All @@ -106,4 +110,4 @@ export async function getAllVersions(server: BdsCorePlatforms) {
return RootData.versions.spigot;
}
throw new Error("Invalid server");
}
}

0 comments on commit 0ffc342

Please sign in to comment.