Update pocketmine list version #497
@ -1,6 +1,5 @@
|
|||||||
import { customChildProcess, httpRequest, httpRequestGithub, httpRequestLarge } from "@sirherobrine23/coreutils";
|
import { customChildProcess, httpRequest, httpRequestGithub, httpRequestLarge } from "@sirherobrine23/coreutils";
|
||||||
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
||||||
import { platformManeger } from "@the-bds-maneger/server_versions";
|
|
||||||
import { existsSync as fsExistsSync, Stats } from "node:fs";
|
import { existsSync as fsExistsSync, Stats } from "node:fs";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
import * as globalPlatfroms from "./globalPlatfroms";
|
import * as globalPlatfroms from "./globalPlatfroms";
|
||||||
@ -9,6 +8,18 @@ import fs from "node:fs/promises";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import AdmZip from "adm-zip";
|
import AdmZip from "adm-zip";
|
||||||
|
|
||||||
|
export async function listVersions() {
|
||||||
|
return (await httpRequestGithub.GithubRelease("pmmp", "PocketMine-MP")).map(data => {
|
||||||
|
const pharFile = data.assets.find(data => data.name.endsWith((".phar")));
|
||||||
|
return {
|
||||||
|
version: data.tag_name,
|
||||||
|
publish: new Date(data.published_at),
|
||||||
|
pharFile: pharFile?.browser_download_url,
|
||||||
|
size: pharFile?.size
|
||||||
|
};
|
||||||
|
}).filter(rel => !!rel.pharFile);
|
||||||
|
}
|
||||||
|
|
||||||
async function findPhp(serverPath: string, extraPath?: string): Promise<string> {
|
async function findPhp(serverPath: string, extraPath?: string): Promise<string> {
|
||||||
if (!extraPath) extraPath = path.join(serverPath, "bin");
|
if (!extraPath) extraPath = path.join(serverPath, "bin");
|
||||||
const files = await Promise.all((await fs.readdir(extraPath)).map(file => fs.lstat(path.join(extraPath, file)).then(stat => ({stat, file, fullPath: path.join(extraPath, file)})).catch(() => {})));
|
const files = await Promise.all((await fs.readdir(extraPath)).map(file => fs.lstat(path.join(extraPath, file)).then(stat => ({stat, file, fullPath: path.join(extraPath, file)})).catch(() => {})));
|
||||||
@ -105,13 +116,15 @@ export async function installServer(version: string|boolean, platformOptions: bd
|
|||||||
platformOptions.withBuildFolder = true;
|
platformOptions.withBuildFolder = true;
|
||||||
const { serverPath, buildFolder, id } = await pathControl("pocketmine", platformOptions);
|
const { serverPath, buildFolder, id } = await pathControl("pocketmine", platformOptions);
|
||||||
await installPhp(serverPath, buildFolder);
|
await installPhp(serverPath, buildFolder);
|
||||||
const info = await platformManeger.pocketmine.find(version);
|
if (typeof version === "boolean") version = "latest";
|
||||||
await httpRequestLarge.saveFile({url: info?.url, filePath: path.join(serverPath, "pocketmine.phar")});
|
if (version?.trim()?.toLowerCase() === "latest") version = (await listVersions()).at(0)?.version
|
||||||
|
const info = (await listVersions()).find(rel => rel.version === version);
|
||||||
|
await httpRequestLarge.saveFile({url: info?.pharFile, filePath: path.join(serverPath, "pocketmine.phar")});
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
version: info.version,
|
version: info.version,
|
||||||
url: info.url,
|
url: info.pharFile,
|
||||||
date: info.date
|
date: info.publish
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user