feat:使用mcim镜像源 统一UA

This commit is contained in:
Tianpao
2025-08-14 13:44:53 +08:00
parent 9d77fa53c7
commit f65dea29f5
6 changed files with 19 additions and 8 deletions

View File

@@ -134,7 +134,7 @@ async function garcol(p:string,fi:ForgeInfo): Promise<void> {
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
try{ try{
LOGGER.info("正在删除垃圾文件......") LOGGER.info("正在删除垃圾文件......")
const x = [`Forge-${fi.minecraft_verison}-${fi.forge_verison}.jar`,`installer.log`,`installer.jar`,`fabric-installer-1.0.3.jar`,`options.txt`,`shaderpacks/`,`resourcepacks/`] const x = [`Forge-${fi.minecraft_verison}-${fi.forge_verison}.jar`,`installer.log`,`installer.jar`,`fabric-installer-1.0.3.jar`,`options.txt`,`shaderpacks/`,`resourcepacks/`,'essential/']
for (let i=0;i<x.length;i++){ for (let i=0;i<x.length;i++){
try{ try{
fs.rmSync(join(p, x[i]),{recursive: true, force: true}) fs.rmSync(join(p, x[i]),{recursive: true, force: true})

View File

@@ -9,7 +9,7 @@ import { LOGGER } from "../utils/logger.js";
const gotx = got.extend({ const gotx = got.extend({
prefixUrl: "https://bmclapi2.bangbang93.com", prefixUrl: "https://bmclapi2.bangbang93.com",
headers: { "User-Agent": "DeEarthX V2" }, headers: { "User-Agent": "DeEarthX" },
}); });
interface mcinfoX { interface mcinfoX {
@@ -24,12 +24,12 @@ export default async function install(
) { ) {
//instance //instance
const mcinfo = (await gotx const mcinfo = (await gotx
.get(`version/${minecraftversion}/json`) .get(`version/${minecraftversion}/json`,{ headers: { "User-Agent": "DeEarthX" } })
.json()) as mcinfoX; //获取Minecraft版本JSON .json()) as mcinfoX; //获取Minecraft版本JSON
const forgepath = path; const forgepath = path;
const forgedata = ( const forgedata = (
await gotx.get( await gotx.get(
`forge/download?mcversion=${minecraftversion}&version=${loaderversion}&category=installer&format=jar` `forge/download?mcversion=${minecraftversion}&version=${loaderversion}&category=installer&format=jar`,
) )
).rawBody; ).rawBody;
fse.outputFileSync( fse.outputFileSync(

View File

@@ -6,7 +6,7 @@ import { LOGGER } from "../utils/logger.js";
import cp from "child_process"; import cp from "child_process";
const got = gotx.extend({ const got = gotx.extend({
prefixUrl: "https://bmclapi2.bangbang93.com", prefixUrl: "https://bmclapi2.bangbang93.com",
headers: { "User-Agent": "DeEarthX V2" }, headers: { "User-Agent": "DeEarthX" },
}); });
interface mcinfoX { interface mcinfoX {

View File

@@ -46,6 +46,7 @@ export class CurseForge implements XPlatform {
"Content-Type": "application/json", "Content-Type": "application/json",
"x-api-key": "x-api-key":
"$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy", "$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy",
"User-Agent": "DeEarthX",
}, },
}) })
.json() .json()

View File

@@ -10,6 +10,7 @@ import fs from "fs";
import toml from 'smol-toml' import toml from 'smol-toml'
import path from 'path'; import path from 'path';
import pMap from "p-map"; import pMap from "p-map";
import { usemirror } from "./utils.js";
import { LOGGER } from "./logger.js"; import { LOGGER } from "./logger.js";
import { MultiBar } from "cli-progress"; import { MultiBar } from "cli-progress";
@@ -136,6 +137,11 @@ export async function DeEarth(modpath: string, movepath: string) {
*/ */
export async function DeEarth(modpath: string, movepath: string) { export async function DeEarth(modpath: string, movepath: string) {
let mrurl = "https://api.modrinth.com"
if (usemirror){
mrurl = "https://mod.mcimirror.top/modrinth"
}
const zipinfo = ZipInfo(modpath) const zipinfo = ZipInfo(modpath)
let modid:string = "" let modid:string = ""
if(zipinfo){ if(zipinfo){
@@ -146,7 +152,7 @@ export async function DeEarth(modpath: string, movepath: string) {
} }
try { //Modrinth try { //Modrinth
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`)) const body = JSON.parse(await FastGot(`${mrurl}/v2/project/${modid}`))
if(body.client_side == "required" && body.server_side !== "required"){ if(body.client_side == "required" && body.server_side !== "required"){
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`) fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
} }
@@ -229,7 +235,7 @@ async function FastGot(url: string) {
try { try {
if (e[0] !== null) { //防止URL为空 if (e[0] !== null) { //防止URL为空
//if(isChinaIpAddress((await got.get("https://4.ipw.cn/")).body)){ //if(isChinaIpAddress((await got.get("https://4.ipw.cn/")).body)){
return (await got.get(e[0], { headers: { "User-Agent": "DeEarth" } })).body return (await got.get(e[0], { headers: { "User-Agent": "DeEarthX" } })).body
//}else{ //}else{
//return (await got.get(`https://mod.mcimirror.top/modrinth/${new URL(e[0]).pathname}`, { headers: { "User-Agent": "DeEarth" } })).body //MCIM源 //return (await got.get(`https://mod.mcimirror.top/modrinth/${new URL(e[0]).pathname}`, { headers: { "User-Agent": "DeEarth" } })).body //MCIM源
//} //}

View File

@@ -153,7 +153,11 @@ export async function xfastdownload(
path !== null && path !== null &&
!fs.existsSync(e[1]) !fs.existsSync(e[1])
) { ) {
const res = (await got.get(e[0])).rawBody; //下载文件 const res = (await got.get(e[0],{
headers: {
"user-agent": "DeEarthX"
}
})).rawBody; //下载文件
await fse.outputFile(e[1], res); //保存文件 await fse.outputFile(e[1], res); //保存文件
} }
}, },