From 0a47d146272b742fa8bb88d332c09aef9e4224c5 Mon Sep 17 00:00:00 2001 From: Tianpao Date: Thu, 1 Jan 2026 20:51:59 +0800 Subject: [PATCH] =?UTF-8?q?chore(HM):=E7=A6=81=E7=94=A8bmclapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/Dex.ts | 4 ++-- backend/src/modloader/fabric.ts | 5 ++++- backend/src/modloader/forge.ts | 23 ++++++++++++++++++++--- backend/src/modloader/minecraft.ts | 6 +++++- backend/src/modloader/neoforge.ts | 27 +++++++++++++++++++++++++-- front/src/component/Setting.vue | 4 ++-- 6 files changed, 58 insertions(+), 11 deletions(-) diff --git a/backend/src/Dex.ts b/backend/src/Dex.ts index 1c090f6..a0413e5 100644 --- a/backend/src/Dex.ts +++ b/backend/src/Dex.ts @@ -25,7 +25,7 @@ export class Dex { public async Main(buffer: Buffer, dser: boolean) { try { const first = Date.now(); - const zps = await this._zps(buffer); + const zps = await this._zips(buffer); const { contain, info } = await zps._getinfo(); const plat = what_platform(contain); logger.debug("Platform detected", plat); @@ -72,7 +72,7 @@ export class Dex { } } - private async _zps(buffer: Buffer) { + private async _zips(buffer: Buffer) { const zip = await yauzl_promise(buffer); const _getinfo = async () => { const importantFiles = ["manifest.json", "modrinth.index.json"]; diff --git a/backend/src/modloader/fabric.ts b/backend/src/modloader/fabric.ts index 31a4825..d313f35 100644 --- a/backend/src/modloader/fabric.ts +++ b/backend/src/modloader/fabric.ts @@ -1,6 +1,7 @@ import got, { Got } from "got"; import fs from "node:fs" import { execPromise, fastdownload } from "../utils/utils.js"; +import config from "../utils/config.js"; interface ILatestLoader{ url:string, @@ -32,7 +33,9 @@ export class Fabric{ async setup():Promise{ await this.installer() - await this.libraries() + if(config.mirror.bmclapi){ + await this.libraries() + } await this.install() await this.wshell() } diff --git a/backend/src/modloader/forge.ts b/backend/src/modloader/forge.ts index eb650bc..757644c 100644 --- a/backend/src/modloader/forge.ts +++ b/backend/src/modloader/forge.ts @@ -4,6 +4,7 @@ import fse from "fs-extra" import { execPromise, fastdownload, version_compare } from "../utils/utils.js"; import { Azip } from "../utils/ziplib.js"; import { execSync } from "node:child_process"; +import config from "../utils/config.js"; interface Iforge{ data:{ @@ -34,14 +35,26 @@ export class Forge { this.loaderVersion = loaderVersion; this.path = path this.got = got.extend({ - prefixUrl: "https://bmclapi2.bangbang93.com", headers: { "User-Agent": "DeEarthX" }, + hooks: { + init: [ + (options) => { + if(config.mirror.bmclapi){ + options.prefixUrl = "https://bmclapi2.bangbang93.com"; + }else{ + options.prefixUrl = "http://maven.minecraftforge.net/"; + } + } + ] + } }) } async setup(){ await this.installer() - await this.library() + if(config.mirror.bmclapi){ + await this.library() + } await this.install() if (version_compare(this.minecraft,"1.18") === -1){ await this.wshell() @@ -84,7 +97,11 @@ export class Forge { } async installer(){ - const res = (await this.got.get(`forge/download?mcversion=${this.minecraft}&version=${this.loaderVersion}&category=installer&format=jar`)).rawBody; + let url = `forge/download?mcversion=${this.minecraft}&version=${this.loaderVersion}&category=installer&format=jar` + if(!config.mirror?.bmclapi){ + url = `net/minecraftforge/forge/${this.minecraft}-${this.loaderVersion}/forge-${this.minecraft}-${this.loaderVersion}-installer.jar` + } + const res = (await this.got.get(url)).rawBody; await fse.outputFile(`${this.path}/forge-${this.minecraft}-${this.loaderVersion}-installer.jar`,res); } diff --git a/backend/src/modloader/minecraft.ts b/backend/src/modloader/minecraft.ts index 6d75bb9..9f99b94 100644 --- a/backend/src/modloader/minecraft.ts +++ b/backend/src/modloader/minecraft.ts @@ -3,6 +3,7 @@ import { fastdownload, version_compare } from "../utils/utils.js"; import { pipeline } from "node:stream/promises"; import got from "got"; import { Azip } from "../utils/ziplib.js"; +import config from "../utils/config.js"; interface ILInfo { libraries: { @@ -27,6 +28,10 @@ export class Minecraft { } async setup() { + await this.eula() //生成Eula.txt + if(!config.mirror.bmclapi){ + return; + } switch (this.loader) { case "forge": await this.forge_setup(); @@ -41,7 +46,6 @@ export class Minecraft { await this.fabric_setup(); break; } - await this.eula() //生成Eula.txt } async forge_setup() { diff --git a/backend/src/modloader/neoforge.ts b/backend/src/modloader/neoforge.ts index c5551b0..8e8e751 100644 --- a/backend/src/modloader/neoforge.ts +++ b/backend/src/modloader/neoforge.ts @@ -1,19 +1,42 @@ import fse from "fs-extra" import { Forge } from "./forge.js"; +import config from "../utils/config.js"; +import { Got,got } from "got"; export class NeoForge extends Forge{ + got: Got; constructor(minecraft:string,loaderVersion:string,path:string){ super(minecraft,loaderVersion,path); //子承父业 + this.got = got.extend({ + headers: { "User-Agent": "DeEarthX" }, + hooks: { + init: [ + (options) => { + if(config.mirror?.bmclapi){ + options.prefixUrl = "https://bmclapi2.bangbang93.com/" + }else{ + options.prefixUrl = "https://maven.neoforged.net/releases/"; + } + } + ] + } + }) } async setup(){ await this.installer(); - await this.library(); + if(config.mirror.bmclapi){ + await this.library(); + } await this.install(); } async installer(){ - const res = (await this.got.get(`neoforge/version/${this.loaderVersion}/download/installer.jar`)).rawBody; + let url = `neoforge/version/${this.loaderVersion}/download/installer.jar`; + if(!config.mirror?.bmclapi){ + url = `net/neoforged/neoforge/${this.loaderVersion}/neoforge-${this.loaderVersion}-installer.jar` + } + const res = (await this.got.get(url)).rawBody; await fse.outputFile(`${this.path}/forge-${this.minecraft}-${this.loaderVersion}-installer.jar`,res); } } \ No newline at end of file diff --git a/front/src/component/Setting.vue b/front/src/component/Setting.vue index 0349e88..6d95a02 100644 --- a/front/src/component/Setting.vue +++ b/front/src/component/Setting.vue @@ -60,8 +60,8 @@ const settings: SettingCategory[] = [ }, { key: 'dexpub', - name: 'DeP过滤', - description: '过滤 DeP 平台中记录的客户端文件', + name: 'DePIS过滤', + description: '过滤 DeEarth Public Info Services 平台中记录的客户端文件', path: 'filter.dexpub', defaultValue: false },