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

@@ -10,6 +10,7 @@ import fs from "fs";
import toml from 'smol-toml'
import path from 'path';
import pMap from "p-map";
import { usemirror } from "./utils.js";
import { LOGGER } from "./logger.js";
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) {
let mrurl = "https://api.modrinth.com"
if (usemirror){
mrurl = "https://mod.mcimirror.top/modrinth"
}
const zipinfo = ZipInfo(modpath)
let modid:string = ""
if(zipinfo){
@@ -146,7 +152,7 @@ export async function DeEarth(modpath: string, movepath: string) {
}
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"){
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
@@ -229,7 +235,7 @@ async function FastGot(url: string) {
try {
if (e[0] !== null) { //防止URL为空
//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{
//return (await got.get(`https://mod.mcimirror.top/modrinth/${new URL(e[0]).pathname}`, { headers: { "User-Agent": "DeEarth" } })).body //MCIM源
//}