Update http request and move versions to core #483
74
package-lock.json
generated
74
package-lock.json
generated
@ -27,6 +27,7 @@
|
|||||||
"@types/tar": "^6.1.3",
|
"@types/tar": "^6.1.3",
|
||||||
"mocha": "^10.1.0",
|
"mocha": "^10.1.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
|
"tsconfig-paths": "^4.1.0",
|
||||||
"typedoc": "^0.23.19",
|
"typedoc": "^0.23.19",
|
||||||
"typescript": "^4.8.4"
|
"typescript": "^4.8.4"
|
||||||
},
|
},
|
||||||
@ -2682,6 +2683,18 @@
|
|||||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
||||||
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
|
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
|
||||||
},
|
},
|
||||||
|
"node_modules/json5": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"json5": "lib/cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/jsonc-parser": {
|
"node_modules/jsonc-parser": {
|
||||||
"version": "3.2.0",
|
"version": "3.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz",
|
||||||
@ -2877,6 +2890,15 @@
|
|||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/minimist": {
|
||||||
|
"version": "1.2.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
||||||
|
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
||||||
|
"dev": true,
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/minipass": {
|
"node_modules/minipass": {
|
||||||
"version": "3.3.5",
|
"version": "3.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.5.tgz",
|
||||||
@ -3692,6 +3714,15 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/strip-bom": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/strip-json-comments": {
|
"node_modules/strip-json-comments": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
|
||||||
@ -3843,6 +3874,20 @@
|
|||||||
"node": ">=0.3.1"
|
"node": ">=0.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tsconfig-paths": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-AHx4Euop/dXFC+Vx589alFba8QItjF+8hf8LtmuiCwHyI4rHXQtOOENaM8kvYf5fR0dRChy3wzWIZ9WbB7FWow==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"json5": "^2.2.1",
|
||||||
|
"minimist": "^1.2.6",
|
||||||
|
"strip-bom": "^3.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/tslib": {
|
"node_modules/tslib": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
|
||||||
@ -6280,6 +6325,12 @@
|
|||||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
|
||||||
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
|
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
|
||||||
},
|
},
|
||||||
|
"json5": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"jsonc-parser": {
|
"jsonc-parser": {
|
||||||
"version": "3.2.0",
|
"version": "3.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz",
|
||||||
@ -6418,6 +6469,12 @@
|
|||||||
"brace-expansion": "^2.0.1"
|
"brace-expansion": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"minimist": {
|
||||||
|
"version": "1.2.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.7.tgz",
|
||||||
|
"integrity": "sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "3.3.5",
|
"version": "3.3.5",
|
||||||
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.5.tgz",
|
||||||
@ -7023,6 +7080,12 @@
|
|||||||
"ansi-regex": "^5.0.1"
|
"ansi-regex": "^5.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"strip-bom": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"strip-json-comments": {
|
"strip-json-comments": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
|
||||||
@ -7124,6 +7187,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"tsconfig-paths": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-AHx4Euop/dXFC+Vx589alFba8QItjF+8hf8LtmuiCwHyI4rHXQtOOENaM8kvYf5fR0dRChy3wzWIZ9WbB7FWow==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"json5": "^2.2.1",
|
||||||
|
"minimist": "^1.2.6",
|
||||||
|
"strip-bom": "^3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tslib": {
|
"tslib": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.1.tgz",
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"docs": "typedoc --readme none --out docs src/index.ts",
|
"docs": "typedoc --readme none --out docs src/index.ts",
|
||||||
"dev": "nodemon",
|
"dev": "nodemon",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test:partial": "mocha -r ts-node/register --exit",
|
"test:partial": "mocha -r ts-node/register -r tsconfig-paths/register --exit",
|
||||||
"test": "npm run test:partial -- 'tests/**/*.ts'"
|
"test": "npm run test:partial -- 'tests/**/*.ts'"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -50,6 +50,7 @@
|
|||||||
"@types/tar": "^6.1.3",
|
"@types/tar": "^6.1.3",
|
||||||
"mocha": "^10.1.0",
|
"mocha": "^10.1.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
|
"tsconfig-paths": "^4.1.0",
|
||||||
"typedoc": "^0.23.19",
|
"typedoc": "^0.23.19",
|
||||||
"typescript": "^4.8.4"
|
"typescript": "^4.8.4"
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import * as globalPlatfroms from "./globalPlatfroms";
|
|||||||
import { platformManeger } from "@the-bds-maneger/server_versions";
|
import { platformManeger } from "@the-bds-maneger/server_versions";
|
||||||
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
||||||
import { commendExists } from "./lib/childPromisses";
|
import { commendExists } from "./lib/childPromisses";
|
||||||
import * as httpRequest from "./lib/httpRequest";
|
import * as httpLarge from "@http/large";
|
||||||
import extendsFs, { exists, readdirrecursive } from "./lib/extendsFs";
|
import extendsFs, { exists, readdirrecursive } from "./lib/extendsFs";
|
||||||
import { randomPort } from "./lib/randomPort";
|
import { randomPort } from "./lib/randomPort";
|
||||||
import { manegerConfigProprieties } from "./configManipulate";
|
import { manegerConfigProprieties } from "./configManipulate";
|
||||||
@ -28,7 +28,7 @@ export async function installServer(version: string|boolean, platformOptions: bd
|
|||||||
await fs.readdir(serverPath).then(files => Promise.all(files.filter(file => !saveFileFolder.test(file)).map(file => fs.rm(path.join(serverPath, file), {recursive: true, force: true}))));
|
await fs.readdir(serverPath).then(files => Promise.all(files.filter(file => !saveFileFolder.test(file)).map(file => fs.rm(path.join(serverPath, file), {recursive: true, force: true}))));
|
||||||
|
|
||||||
const serverConfigProperties = (await fs.readFile(path.join(serverPath, "server.properties"), "utf8").catch(() => "")).trim();
|
const serverConfigProperties = (await fs.readFile(path.join(serverPath, "server.properties"), "utf8").catch(() => "")).trim();
|
||||||
await httpRequest.extractZip({url, folderTarget: serverPath});
|
await httpLarge.extractZip({url, folderTarget: serverPath});
|
||||||
if (serverConfigProperties) await fs.writeFile(path.join(serverPath, "server.properties"), serverConfigProperties);
|
if (serverConfigProperties) await fs.writeFile(path.join(serverPath, "server.properties"), serverConfigProperties);
|
||||||
await fs.writeFile(path.join(serverRoot, "version_installed.json"), JSON.stringify({version: bedrockData.version, date: bedrockData.date, installDate: new Date()}));
|
await fs.writeFile(path.join(serverRoot, "version_installed.json"), JSON.stringify({version: bedrockData.version, date: bedrockData.date, installDate: new Date()}));
|
||||||
|
|
||||||
@ -286,4 +286,4 @@ export async function addResourcePacksToWorld(resourceId: string, platformOption
|
|||||||
resourcesData.push({pack_id: packInfo.header.uuid, version: packInfo.header.version});
|
resourcesData.push({pack_id: packInfo.header.uuid, version: packInfo.header.version});
|
||||||
await fs.writeFile(path.join(serverPath, "worlds", serverConfigObject["level-name"], "world_resource_packs.json"), JSON.stringify(resourcesData, null, 2));
|
await fs.writeFile(path.join(serverPath, "worlds", serverConfigObject["level-name"], "world_resource_packs.json"), JSON.stringify(resourcesData, null, 2));
|
||||||
return resourcesData;
|
return resourcesData;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import fs from "node:fs/promises";
|
|||||||
import tar from "tar";
|
import tar from "tar";
|
||||||
import { bdsRoot } from "./platformPathManeger";
|
import { bdsRoot } from "./platformPathManeger";
|
||||||
import { exists } from "./lib/extendsFs";
|
import { exists } from "./lib/extendsFs";
|
||||||
import { getExternalIP } from "./lib/httpRequest";
|
import { getExternalIP } from "@http/client";
|
||||||
|
|
||||||
export type payload = {
|
export type payload = {
|
||||||
httpVersion?: string,
|
httpVersion?: string,
|
||||||
@ -153,4 +153,4 @@ export async function importBds(option: {host: string, port: number, authToken:
|
|||||||
tar_extract.on("error", reject);
|
tar_extract.on("error", reject);
|
||||||
socket.once("close", () => tar_extract.on("finish", done));
|
socket.once("close", () => tar_extract.on("finish", done));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
18
src/index.ts
18
src/index.ts
@ -1,5 +1,10 @@
|
|||||||
|
// HTTP
|
||||||
|
import * as httpSimples from "@http/simples";
|
||||||
|
import * as httpLarge from "@http/large";
|
||||||
|
import * as httpGithub from "@http/github";
|
||||||
|
import * as httpClient from "@http/client";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import * as httpRequest from "./lib/httpRequest";
|
|
||||||
import * as platformPathManeger from "./platformPathManeger"
|
import * as platformPathManeger from "./platformPathManeger"
|
||||||
import * as globalPlatfroms from "./globalPlatfroms";
|
import * as globalPlatfroms from "./globalPlatfroms";
|
||||||
import * as pluginManeger from "./plugin/plugin";
|
import * as pluginManeger from "./plugin/plugin";
|
||||||
@ -15,7 +20,7 @@ import * as Spigot from "./spigot";
|
|||||||
import * as Powernukkit from "./pwnuukit";
|
import * as Powernukkit from "./pwnuukit";
|
||||||
import * as PaperMC from "./paper";
|
import * as PaperMC from "./paper";
|
||||||
|
|
||||||
export {platformPathManeger, globalPlatfroms, pluginManeger, export_import, PocketmineMP, pluginHooks, Powernukkit, httpRequest, PaperMC, Bedrock, Spigot, proxy, Java};
|
export {platformPathManeger, globalPlatfroms, pluginManeger, export_import, PocketmineMP, pluginHooks, Powernukkit, PaperMC, Bedrock, Spigot, proxy, Java};
|
||||||
export default {
|
export default {
|
||||||
Bedrock,
|
Bedrock,
|
||||||
Java,
|
Java,
|
||||||
@ -28,8 +33,13 @@ export default {
|
|||||||
globalPlatfroms,
|
globalPlatfroms,
|
||||||
pluginManeger,
|
pluginManeger,
|
||||||
pluginHooks,
|
pluginHooks,
|
||||||
httpRequest,
|
|
||||||
export_import,
|
export_import,
|
||||||
proxy
|
proxy,
|
||||||
|
httpRequest: {
|
||||||
|
httpSimples,
|
||||||
|
httpLarge,
|
||||||
|
httpGithub,
|
||||||
|
httpClient
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ import fsOld from "node:fs";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import { platformManeger } from "@the-bds-maneger/server_versions";
|
import { platformManeger } from "@the-bds-maneger/server_versions";
|
||||||
import { actionV2, actionsV2 } from "./globalPlatfroms";
|
import { actionV2, actionsV2 } from "./globalPlatfroms";
|
||||||
import { saveFile } from "./lib/httpRequest";
|
import { saveFile } from "@http/large";
|
||||||
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
||||||
import { manegerConfigProprieties } from "./configManipulate";
|
import { manegerConfigProprieties } from "./configManipulate";
|
||||||
import { randomPort } from "./lib/randomPort";
|
import { randomPort } from "./lib/randomPort";
|
||||||
@ -181,4 +181,4 @@ export async function serverConfig(platformOptions: bdsPlatformOptions = {id: "d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,236 +0,0 @@
|
|||||||
import type { Method } from "got";
|
|
||||||
import os from "node:os";
|
|
||||||
import fs from "node:fs";
|
|
||||||
import path from "node:path";
|
|
||||||
import crypto from "node:crypto";
|
|
||||||
import tar from "tar";
|
|
||||||
import AdmZip from "adm-zip";
|
|
||||||
import stream from "node:stream";
|
|
||||||
import { exists } from "./extendsFs";
|
|
||||||
|
|
||||||
let got: (typeof import("got"))["default"];
|
|
||||||
const gotCjs = async () => got||(await (eval('import("got")') as Promise<typeof import("got")>)).default.extend({enableUnixSockets: true});
|
|
||||||
gotCjs().then(res => got = res);
|
|
||||||
|
|
||||||
export type requestOptions = {
|
|
||||||
url?: string,
|
|
||||||
socket?: {
|
|
||||||
socketPath: string,
|
|
||||||
path?: string,
|
|
||||||
}
|
|
||||||
method?: Method,
|
|
||||||
headers?: {[headerName: string]: string[]|string},
|
|
||||||
body?: any,
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function pipeFetch(options: requestOptions & {stream: fs.WriteStream|stream.Writable, waitFinish?: boolean}) {
|
|
||||||
if (!(options?.url||options?.socket)) throw new Error("Host blank")
|
|
||||||
const urlRequest = (typeof options.url === "string")?options.url:`http://unix:${options.socket.socketPath}:${options.socket.path||"/"}`;
|
|
||||||
const gotStream = (await gotCjs()).stream(urlRequest, {
|
|
||||||
isStream: true,
|
|
||||||
headers: options.headers||{},
|
|
||||||
method: options.method||"GET",
|
|
||||||
json: options.body,
|
|
||||||
});
|
|
||||||
await new Promise<void>((done, reject) => {
|
|
||||||
gotStream.pipe(options.stream);
|
|
||||||
options.stream.on("error", reject);
|
|
||||||
gotStream.on("error", reject);
|
|
||||||
gotStream.once("end", () => {
|
|
||||||
if (options.waitFinish) return options.stream.once("finish", done);
|
|
||||||
return done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function bufferFetch(options: string|requestOptions) {
|
|
||||||
if (typeof options === "string") options = {url: options};
|
|
||||||
if (!(options.url||options.socket)) throw new Error("Host blank")
|
|
||||||
const urlRequest = (typeof options.url === "string")?options.url:`http://unix:${options.socket.socketPath}:${options.socket.path||"/"}`;
|
|
||||||
return (await gotCjs())(urlRequest, {
|
|
||||||
headers: options.headers||{},
|
|
||||||
method: options.method||"GET",
|
|
||||||
json: options.body,
|
|
||||||
responseType: "buffer",
|
|
||||||
}).then(res => ({headers: res.headers, data: Buffer.from(res.body), response: res}));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getJSON<JSONReturn = any>(request: string|requestOptions): Promise<JSONReturn> {
|
|
||||||
if (typeof request === "string") request = {url: request};
|
|
||||||
const res = (await bufferFetch(request)).data.toString("utf8");
|
|
||||||
return JSON.parse(res) as JSONReturn;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function saveFile(request: string|requestOptions & {filePath?: string}) {
|
|
||||||
if (typeof request === "string") request = {url: request};
|
|
||||||
const filePath = request.filePath||path.join(os.tmpdir(), `raw_bdscore_${Date.now()}_${(path.parse(request.url||request.socket?.path||crypto.randomBytes(16).toString("hex"))).name}`);
|
|
||||||
await pipeFetch({...request, waitFinish: true, stream: fs.createWriteStream(filePath, {autoClose: false})});
|
|
||||||
return filePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function tarExtract(request: requestOptions & {folderPath?: string}) {
|
|
||||||
const folderToExtract = request.folderPath||path.join(os.tmpdir(), `raw_bdscore_${Date.now()}_${(path.parse(request.url||request.socket?.path||crypto.randomBytes(16).toString("hex"))).name}`);
|
|
||||||
if (!await exists(folderToExtract)) await fs.promises.mkdir(folderToExtract, {recursive: true});
|
|
||||||
await pipeFetch({
|
|
||||||
...request,
|
|
||||||
waitFinish: true,
|
|
||||||
stream: tar.extract({
|
|
||||||
cwd: folderToExtract,
|
|
||||||
noChmod: false,
|
|
||||||
noMtime: false,
|
|
||||||
preserveOwner: true,
|
|
||||||
keep: true,
|
|
||||||
p: true
|
|
||||||
})
|
|
||||||
});
|
|
||||||
return folderToExtract
|
|
||||||
}
|
|
||||||
|
|
||||||
const githubAchive = /github.com\/[\S\w]+\/[\S\w]+\/archive\//;
|
|
||||||
export async function extractZip(request: requestOptions & {folderTarget: string}) {
|
|
||||||
const zip = new AdmZip(await saveFile(request));
|
|
||||||
const targetFolder = githubAchive.test(request.url)?await fs.promises.mkdtemp(path.join(os.tmpdir(), "githubRoot_"), "utf8"):request.folderTarget;
|
|
||||||
await new Promise<void>((done, reject) => {
|
|
||||||
zip.extractAllToAsync(targetFolder, true, true, (err) => {
|
|
||||||
if (!err) return done();
|
|
||||||
return reject(err);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
if (githubAchive.test(request.url)) {
|
|
||||||
const files = await fs.promises.readdir(targetFolder);
|
|
||||||
if (files.length === 0) throw new Error("Invalid extract");
|
|
||||||
await fs.promises.cp(path.join(targetFolder, files[0]), request.folderTarget, {recursive: true, force: true, preserveTimestamps: true, verbatimSymlinks: true});
|
|
||||||
return await fs.promises.rm(targetFolder, {recursive: true, force: true});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type testIp<protocolType extends "ipv4"|"ipv6" = "ipv4"> = {
|
|
||||||
ip: string,
|
|
||||||
type: protocolType,
|
|
||||||
subtype: string,
|
|
||||||
via: string,
|
|
||||||
padding: string,
|
|
||||||
asn: string,
|
|
||||||
asnlist: string,
|
|
||||||
asn_name: string,
|
|
||||||
country: string,
|
|
||||||
protocol: "HTTP/2.0"|"HTTP/1.1"|"HTTP/1.0"
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function getExternalIP(): Promise<{ipv4: string, ipv6?: string, rawRequest?: {ipv4: testIp<"ipv4">, ipv6?: testIp<"ipv6">}}> {
|
|
||||||
const ipv6: testIp<"ipv6"> = await getJSON("https://ipv6.lookup.test-ipv6.com/ip/").catch(() => undefined);
|
|
||||||
const ipv4: testIp<"ipv4"> = await getJSON("https://ipv4.lookup.test-ipv6.com/ip/");
|
|
||||||
return {
|
|
||||||
ipv4: ipv4.ip,
|
|
||||||
ipv6: ipv6?.ip,
|
|
||||||
rawRequest: {ipv4, ipv6}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export type githubRelease = {
|
|
||||||
url: string;
|
|
||||||
assets_url: string;
|
|
||||||
upload_url: string;
|
|
||||||
html_url: string;
|
|
||||||
id: number;
|
|
||||||
tarball_url: string;
|
|
||||||
zipball_url: string;
|
|
||||||
body: string;
|
|
||||||
author: {
|
|
||||||
login: string;
|
|
||||||
id: number;
|
|
||||||
node_id: string;
|
|
||||||
avatar_url: string;
|
|
||||||
gravatar_id: string;
|
|
||||||
url: string;
|
|
||||||
html_url: string;
|
|
||||||
followers_url: string;
|
|
||||||
following_url: string;
|
|
||||||
gists_url: string;
|
|
||||||
starred_url: string;
|
|
||||||
subscriptions_url: string;
|
|
||||||
organizations_url: string;
|
|
||||||
repos_url: string;
|
|
||||||
events_url: string;
|
|
||||||
received_events_url: string;
|
|
||||||
type: string;
|
|
||||||
site_admin: boolean;
|
|
||||||
};
|
|
||||||
node_id: string;
|
|
||||||
tag_name: string;
|
|
||||||
target_commitish: string;
|
|
||||||
name: string;
|
|
||||||
draft: boolean;
|
|
||||||
prerelease: boolean;
|
|
||||||
created_at: string;
|
|
||||||
published_at: string;
|
|
||||||
assets: Array<{
|
|
||||||
url: string;
|
|
||||||
id: number;
|
|
||||||
node_id: string;
|
|
||||||
name: string;
|
|
||||||
label: string;
|
|
||||||
content_type: string;
|
|
||||||
state: string;
|
|
||||||
size: number;
|
|
||||||
download_count: number;
|
|
||||||
created_at: string;
|
|
||||||
updated_at: string;
|
|
||||||
browser_download_url: string;
|
|
||||||
uploader: {
|
|
||||||
login: string;
|
|
||||||
id: number;
|
|
||||||
node_id: string;
|
|
||||||
avatar_url: string;
|
|
||||||
gravatar_id: string;
|
|
||||||
url: string;
|
|
||||||
html_url: string;
|
|
||||||
followers_url: string;
|
|
||||||
following_url: string;
|
|
||||||
gists_url: string;
|
|
||||||
starred_url: string;
|
|
||||||
subscriptions_url: string;
|
|
||||||
organizations_url: string;
|
|
||||||
repos_url: string;
|
|
||||||
events_url: string;
|
|
||||||
received_events_url: string;
|
|
||||||
type: string;
|
|
||||||
site_admin: boolean;
|
|
||||||
};
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function GithubRelease(username: string, repo: string, releaseTag: string): Promise<githubRelease>;
|
|
||||||
export async function GithubRelease(username: string, repo: string): Promise<githubRelease[]>;
|
|
||||||
export async function GithubRelease(username: string): Promise<githubRelease[]>;
|
|
||||||
export async function GithubRelease(username: string, repo?: string, releaseTag?: string): Promise<githubRelease|githubRelease[]> {
|
|
||||||
let fullRepo = username;
|
|
||||||
if (!username) throw new Error("Repository is required, example: GithubRelease(\"Username/repo\") or GithubRelease(\"Username\", \"repo\")");
|
|
||||||
if (repo) {
|
|
||||||
if (!/\//.test(fullRepo)) fullRepo += "/"+repo;
|
|
||||||
}
|
|
||||||
if (releaseTag) return getJSON<githubRelease>(`https://api.github.com/repos/${fullRepo}/releases/tags/${releaseTag}`);
|
|
||||||
return getJSON<githubRelease[]>(`https://api.github.com/repos/${fullRepo}/releases?per_page=100`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export type githubTree = {
|
|
||||||
"sha": string,
|
|
||||||
"url": string,
|
|
||||||
"truncated": boolean,
|
|
||||||
"tree": {
|
|
||||||
"path": string,
|
|
||||||
"mode": string,
|
|
||||||
"type": "blob"|"tree",
|
|
||||||
"sha": string,
|
|
||||||
"size": number,
|
|
||||||
"url": string
|
|
||||||
}[],
|
|
||||||
};
|
|
||||||
export async function githubTree(username: string, repo: string, tree: string = "main") {
|
|
||||||
const validate = /^[a-zA-Z0-9_\-]+$/;
|
|
||||||
if (!validate.test(username)) throw new Error("Invalid username");
|
|
||||||
if (!validate.test(repo)) throw new Error("Invalid repository name");
|
|
||||||
return getJSON<githubTree>(`https://api.github.com/repos/${username}/${repo}/git/trees/${tree}?recursive=true`);
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ import {spigot} from "../db/spigot";
|
|||||||
export const urlRegex = /http[s]:\/\/.*/;
|
export const urlRegex = /http[s]:\/\/.*/;
|
||||||
async function Find() {
|
async function Find() {
|
||||||
const { document } = (new jsdom.JSDOM(await bufferFetch("https://getbukkit.org/download/spigot").then(({data}) => data.toString("utf8")).catch(err => {console.log(err); return "<html></html>"}))).window;
|
const { document } = (new jsdom.JSDOM(await bufferFetch("https://getbukkit.org/download/spigot").then(({data}) => data.toString("utf8")).catch(err => {console.log(err); return "<html></html>"}))).window;
|
||||||
const Versions = await Promise.all(([...document.querySelectorAll("#download > div > div > div > div")]).map(async DOM => {
|
const Versions = await Promise.all(([...(document.querySelectorAll("#download > div > div > div > div") as any)]).map(async DOM => {
|
||||||
const download = (new jsdom.JSDOM(await bufferFetch(DOM.querySelector("div > div.col-sm-4 > div.btn-group > a")["href"]).then(({data}) => data.toString("utf8"))));
|
const download = (new jsdom.JSDOM(await bufferFetch(DOM.querySelector("div > div.col-sm-4 > div.btn-group > a")["href"]).then(({data}) => data.toString("utf8"))));
|
||||||
const serverInfo = {
|
const serverInfo = {
|
||||||
version: String(DOM.querySelector("div:nth-child(1) > h2").textContent),
|
version: String(DOM.querySelector("div:nth-child(1) > h2").textContent),
|
||||||
|
@ -5,7 +5,7 @@ import os from "node:os";
|
|||||||
import Proprieties from "./lib/Proprieties";
|
import Proprieties from "./lib/Proprieties";
|
||||||
import * as globalPlatfroms from "./globalPlatfroms";
|
import * as globalPlatfroms from "./globalPlatfroms";
|
||||||
import { platformManeger } from "@the-bds-maneger/server_versions";
|
import { platformManeger } from "@the-bds-maneger/server_versions";
|
||||||
import { saveFile } from "./lib/httpRequest";
|
import { saveFile } from "@http/large";
|
||||||
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
||||||
import { spigotProprieties } from "./spigot";
|
import { spigotProprieties } from "./spigot";
|
||||||
|
|
||||||
@ -115,4 +115,4 @@ export async function updateConfig(config: {key: string, value: any}, platformOp
|
|||||||
const { serverPath } = await pathControl("paper", platformOptions);
|
const { serverPath } = await pathControl("paper", platformOptions);
|
||||||
currentConfig[config.key] = config.value;
|
currentConfig[config.key] = config.value;
|
||||||
return fs.writeFile(path.join(serverPath, "server.properties"), Proprieties.stringify(currentConfig));
|
return fs.writeFile(path.join(serverPath, "server.properties"), Proprieties.stringify(currentConfig));
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import path from "node:path";
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import { actionsV2 } from "../globalPlatfroms";
|
import { actionsV2 } from "../globalPlatfroms";
|
||||||
import { execFileAsync } from "../lib/childPromisses";
|
import { execFileAsync } from "../lib/childPromisses";
|
||||||
import { saveFile } from "../lib/httpRequest";
|
import { saveFile } from "@http/large";
|
||||||
|
|
||||||
export type hooksPlatform = "bedrock"|"java"|"pocketmine"|"spigot"|"powernukkit"|"paper";
|
export type hooksPlatform = "bedrock"|"java"|"pocketmine"|"spigot"|"powernukkit"|"paper";
|
||||||
export type hooksPlatformGeneric = hooksPlatform|"generic";
|
export type hooksPlatformGeneric = hooksPlatform|"generic";
|
||||||
@ -80,4 +80,4 @@ export class script_hook {
|
|||||||
this.#localFolder = hookFolder;
|
this.#localFolder = hookFolder;
|
||||||
if (platformActions) this.#loadLocalScript();
|
if (platformActions) this.#loadLocalScript();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import * as http_request from "../lib/httpRequest";
|
|
||||||
import type { bdsPlatform } from "../platformPathManeger";
|
import type { bdsPlatform } from "../platformPathManeger";
|
||||||
|
import { getJSON } from "@http/simples";
|
||||||
|
import { saveFile } from "@http/large";
|
||||||
|
|
||||||
export type pluginConfig = {
|
export type pluginConfig = {
|
||||||
version?: 1,
|
version?: 1,
|
||||||
@ -40,11 +41,11 @@ export class pluginManeger {
|
|||||||
const urlandbds = /http[s]:\/\/|bdsplugin:\/\//;
|
const urlandbds = /http[s]:\/\/|bdsplugin:\/\//;
|
||||||
if (/bdsplugin:\/\//.test(plugin)) plugin = `https://raw.githubusercontent.com/The-Bds-Maneger/plugin_list/main/plugins/${plugin.replace(urlandbds, "").replace(".json", "")}.json`;
|
if (/bdsplugin:\/\//.test(plugin)) plugin = `https://raw.githubusercontent.com/The-Bds-Maneger/plugin_list/main/plugins/${plugin.replace(urlandbds, "").replace(".json", "")}.json`;
|
||||||
else if (!/http[s]:\/\/\//.test(plugin)) plugin = "bdsplugin://"+plugin;
|
else if (!/http[s]:\/\/\//.test(plugin)) plugin = "bdsplugin://"+plugin;
|
||||||
const info = await http_request.getJSON<pluginConfig|pluginV2>(plugin);
|
const info = await getJSON<pluginConfig|pluginV2>(plugin);
|
||||||
if (info.version === 2) {
|
if (info.version === 2) {
|
||||||
const platformData = info.platform[this.#platform];
|
const platformData = info.platform[this.#platform];
|
||||||
if (!platformData) throw new Error("Platform not supported to Plugin!");
|
if (!platformData) throw new Error("Platform not supported to Plugin!");
|
||||||
await http_request.saveFile({
|
await saveFile({
|
||||||
url: platformData.url,
|
url: platformData.url,
|
||||||
filePath: path.join(this.#pluginFolder, platformData.fileName||path.basename(platformData.url))
|
filePath: path.join(this.#pluginFolder, platformData.fileName||path.basename(platformData.url))
|
||||||
});
|
});
|
||||||
@ -52,10 +53,10 @@ export class pluginManeger {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!info.platforms.includes(this.#platform)) throw new Error("Platform not supported to Plugin!");
|
if (!info.platforms.includes(this.#platform)) throw new Error("Platform not supported to Plugin!");
|
||||||
await http_request.saveFile({
|
await saveFile({
|
||||||
url: info.url,
|
url: info.url,
|
||||||
filePath: path.join(this.#pluginFolder, info.fileName||path.basename(info.url))
|
filePath: path.join(this.#pluginFolder, info.fileName||path.basename(info.url))
|
||||||
});
|
});
|
||||||
if (info.dependecies) await Promise.all(info.dependecies.map(dep => this.installPlugin(dep)));
|
if (info.dependecies) await Promise.all(info.dependecies.map(dep => this.installPlugin(dep)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -7,8 +7,10 @@ import { existsSync as fsExistsSync, Stats } from "node:fs";
|
|||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
import { platformManeger } from "@the-bds-maneger/server_versions";
|
import { platformManeger } from "@the-bds-maneger/server_versions";
|
||||||
import { execFileAsync, execAsync } from "./lib/childPromisses";
|
import { execFileAsync, execAsync } from "./lib/childPromisses";
|
||||||
import * as httpRequest from "./lib/httpRequest";
|
import { extractZip, saveFile, tarExtract } from "@http/large";
|
||||||
|
import { bufferFetch } from "@http/simples";
|
||||||
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
||||||
|
import {GithubRelease, githubRelease} from "@http/github";
|
||||||
|
|
||||||
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");
|
||||||
@ -57,7 +59,7 @@ async function buildPhp(serverPath: string, buildFolder: string) {
|
|||||||
await promisify((new AdmZip(path.join(buildFolder, (await fs.readdir(buildFolder)).find(file => file.endsWith(".zip"))))).extractAllToAsync)(serverPath, false, true);
|
await promisify((new AdmZip(path.join(buildFolder, (await fs.readdir(buildFolder)).find(file => file.endsWith(".zip"))))).extractAllToAsync)(serverPath, false, true);
|
||||||
} else {
|
} else {
|
||||||
const buildFile = path.join(buildFolder, "build.sh");
|
const buildFile = path.join(buildFolder, "build.sh");
|
||||||
await fs.writeFile(buildFile, (await httpRequest.bufferFetch({url: "https://raw.githubusercontent.com/pmmp/php-build-scripts/stable/compile.sh"})).data);
|
await fs.writeFile(buildFile, (await bufferFetch({url: "https://raw.githubusercontent.com/pmmp/php-build-scripts/stable/compile.sh"})).data);
|
||||||
await fs.chmod(buildFile, "777");
|
await fs.chmod(buildFile, "777");
|
||||||
await execFileAsync(buildFile, ["-j"+os.cpus().length], {cwd: buildFolder, stdio: "inherit"});
|
await execFileAsync(buildFile, ["-j"+os.cpus().length], {cwd: buildFolder, stdio: "inherit"});
|
||||||
await fs.cp(path.join(buildFolder, "bin", (await fs.readdir(path.join(buildFolder, "bin")))[0]), path.join(serverPath, "bin"), {force: true, recursive: true, preserveTimestamps: true, verbatimSymlinks: true});
|
await fs.cp(path.join(buildFolder, "bin", (await fs.readdir(path.join(buildFolder, "bin")))[0]), path.join(serverPath, "bin"), {force: true, recursive: true, preserveTimestamps: true, verbatimSymlinks: true});
|
||||||
@ -67,20 +69,20 @@ async function buildPhp(serverPath: string, buildFolder: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function installPhp(serverPath: string, buildFolder: string): Promise<void> {
|
async function installPhp(serverPath: string, buildFolder: string): Promise<void> {
|
||||||
const releases: (httpRequest.githubRelease["assets"][0])[] = [];
|
const releases: (githubRelease["assets"][0])[] = [];
|
||||||
(await httpRequest.GithubRelease("The-Bds-Maneger", "Build-PHP-Bins")).map(re => re.assets).forEach(res => releases.push(...res));
|
(await GithubRelease("The-Bds-Maneger", "Build-PHP-Bins")).map(re => re.assets).forEach(res => releases.push(...res));
|
||||||
if (fsExistsSync(path.resolve(serverPath, "bin"))) await fs.rm(path.resolve(serverPath, "bin"), {recursive: true});
|
if (fsExistsSync(path.resolve(serverPath, "bin"))) await fs.rm(path.resolve(serverPath, "bin"), {recursive: true});
|
||||||
await fs.writeFile(path.join(os.tmpdir(), "bds_test.php"), `<?php echo "Hello World";`);
|
await fs.writeFile(path.join(os.tmpdir(), "bds_test.php"), `<?php echo "Hello World";`);
|
||||||
if (process.platform === "win32") {
|
if (process.platform === "win32") {
|
||||||
let url: string = releases.filter(assert => assert.name.endsWith(".zip")).find(assert => /win32|windows/.test(assert.name))?.browser_download_url;
|
let url: string = releases.filter(assert => assert.name.endsWith(".zip")).find(assert => /win32|windows/.test(assert.name))?.browser_download_url;
|
||||||
if (!url) throw new Error("Cannnot get php url");
|
if (!url) throw new Error("Cannnot get php url");
|
||||||
return promisify((new AdmZip(await httpRequest.saveFile({url}))).extractAllToAsync)(serverPath, false, true);
|
return promisify((new AdmZip(await saveFile({url}))).extractAllToAsync)(serverPath, false, true);
|
||||||
} else {
|
} else {
|
||||||
const fileTest = RegExp(`${process.platform.toLowerCase()}.*${process.arch.toLowerCase()}`);
|
const fileTest = RegExp(`${process.platform.toLowerCase()}.*${process.arch.toLowerCase()}`);
|
||||||
const file = releases.find(re => fileTest.test(re.name.toLowerCase()));
|
const file = releases.find(re => fileTest.test(re.name.toLowerCase()));
|
||||||
if (file) {
|
if (file) {
|
||||||
if (/\.zip/.test(file.name)) await httpRequest.extractZip({url: file.browser_download_url, folderTarget: serverPath});
|
if (/\.zip/.test(file.name)) await extractZip({url: file.browser_download_url, folderTarget: serverPath});
|
||||||
else await httpRequest.tarExtract({url: file.browser_download_url, folderPath: path.join(serverPath, "bin")});
|
else await tarExtract({url: file.browser_download_url, folderPath: path.join(serverPath, "bin")});
|
||||||
|
|
||||||
// Update zts
|
// Update zts
|
||||||
if (process.platform === "linux"||process.platform === "android"||process.platform === "darwin") {
|
if (process.platform === "linux"||process.platform === "android"||process.platform === "darwin") {
|
||||||
@ -107,7 +109,7 @@ export async function installServer(version: string|boolean, platformOptions: bd
|
|||||||
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);
|
const info = await platformManeger.pocketmine.find(version);
|
||||||
await httpRequest.saveFile({url: info?.url, filePath: path.join(serverPath, "pocketmine.phar")});
|
await saveFile({url: info?.url, filePath: path.join(serverPath, "pocketmine.phar")});
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
version: info.version,
|
version: info.version,
|
||||||
@ -151,4 +153,4 @@ export async function startServer(platformOptions: bdsPlatformOptions = {id: "de
|
|||||||
processConfig: {command: await findPhp(serverPath), args: [serverPhar, "--no-wizard", "--enable-ansi"], options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}},
|
processConfig: {command: await findPhp(serverPath), args: [serverPhar, "--no-wizard", "--enable-ansi"], options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}},
|
||||||
hooks: pocketmineHooks
|
hooks: pocketmineHooks
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import fs from "node:fs/promises";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import * as globalPlatfroms from "./globalPlatfroms";
|
import * as globalPlatfroms from "./globalPlatfroms";
|
||||||
import { platformManeger } from "@the-bds-maneger/server_versions";
|
import { platformManeger } from "@the-bds-maneger/server_versions";
|
||||||
import { saveFile } from "./lib/httpRequest";
|
import { saveFile } from "@http/large";
|
||||||
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
||||||
|
|
||||||
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
|
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
|
||||||
|
@ -3,7 +3,9 @@ import fs from "node:fs/promises";
|
|||||||
import fsOld from "node:fs";
|
import fsOld from "node:fs";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import * as globalPlatfroms from "./globalPlatfroms";
|
import * as globalPlatfroms from "./globalPlatfroms";
|
||||||
import { bufferFetch, getJSON, GithubRelease, saveFile } from "./lib/httpRequest";
|
import { bufferFetch, getJSON } from "@http/simples";
|
||||||
|
import { saveFile } from "@http/large";
|
||||||
|
import { GithubRelease } from "@http/github";
|
||||||
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
|
||||||
import Proprieties from "./lib/Proprieties"
|
import Proprieties from "./lib/Proprieties"
|
||||||
|
|
||||||
@ -194,4 +196,4 @@ export async function updateConfig(config: {key: string, value: any}, platformOp
|
|||||||
const { serverPath } = await pathControl("spigot", platformOptions);
|
const { serverPath } = await pathControl("spigot", platformOptions);
|
||||||
currentConfig[config.key] = config.value;
|
currentConfig[config.key] = config.value;
|
||||||
return fs.writeFile(path.join(serverPath, "server.properties"), Proprieties.stringify(currentConfig));
|
return fs.writeFile(path.join(serverPath, "server.properties"), Proprieties.stringify(currentConfig));
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import stream from "node:stream";
|
import stream from "node:stream";
|
||||||
import { getExternalIP, getJSON, saveFile, pipeFetch, githubTree, GithubRelease } from "../../src/lib/httpRequest";
|
import { getJSON, pipeFetch } from "../../src/lib/request/simples";
|
||||||
|
import { saveFile } from "../../src/lib/request/large";
|
||||||
|
import { GithubRelease, githubTree } from "../../src/lib/request/github";
|
||||||
|
import { getExternalIP } from "../../src/lib/request/client";
|
||||||
|
|
||||||
describe("HTTP Request", function(){
|
describe("HTTP Request", function(){
|
||||||
this.timeout(Infinity);
|
this.timeout(Infinity);
|
||||||
const Stream = new stream.Writable({write(chunk, encoding, callback) {callback()}});
|
const Stream = new stream.Writable({write(_chunk, _encoding, callback) {callback()}});
|
||||||
it("External IP", async () => getExternalIP());
|
it("External IP", async () => getExternalIP());
|
||||||
it("Github Releases", async () => GithubRelease("The-Bds-Maneger", "Bds-Maneger-Core"));
|
it("Github Releases", async () => GithubRelease("The-Bds-Maneger", "Bds-Maneger-Core"));
|
||||||
it("Github Tree", async () => githubTree("The-Bds-Maneger", "Bds-Maneger-Core"));
|
it("Github Tree", async () => githubTree("The-Bds-Maneger", "Bds-Maneger-Core"));
|
||||||
it("JSON", async () => getJSON("https://raw.githubusercontent.com/The-Bds-Maneger/Bds-Maneger-Core/main/package.json"));
|
it("JSON", async () => getJSON("https://raw.githubusercontent.com/The-Bds-Maneger/Bds-Maneger-Core/main/package.json"));
|
||||||
it("Stream", async () => pipeFetch({stream: Stream, url: "https://raw.githubusercontent.com/The-Bds-Maneger/Bds-Maneger-Core/main/package.json"}));
|
it("Stream", async () => pipeFetch({stream: Stream, url: "https://raw.githubusercontent.com/The-Bds-Maneger/Bds-Maneger-Core/main/package.json"}));
|
||||||
it("Save File", async () => saveFile("https://raw.githubusercontent.com/The-Bds-Maneger/Bds-Maneger-Core/main/package.json"));
|
it("Save File", async () => saveFile("https://raw.githubusercontent.com/The-Bds-Maneger/Bds-Maneger-Core/main/package.json"));
|
||||||
});
|
});
|
||||||
|
@ -15,15 +15,11 @@
|
|||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@http/*": [
|
"@http/*": [
|
||||||
"./src/lib/request/*"
|
"src/lib/request/*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*"
|
"src/**/*"
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"node_modules/",
|
|
||||||
"tests/"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user