Compare commits

..

4 Commits

Author SHA1 Message Date
Tianpao
f65dea29f5 feat:使用mcim镜像源 统一UA 2025-08-14 13:44:53 +08:00
Tianpao
9d77fa53c7 feat:fabric启动脚本,垃圾回收,rubbish改名 fix:json解析失败崩溃 2025-07-26 16:27:14 +08:00
Tianpao
d8d8c4051a feat:更新fabric安装器 2025-07-26 15:11:44 +08:00
Tianpao
32f7473533 fix:DEP无法正常抛出错误 2025-07-26 13:29:47 +08:00
7 changed files with 61 additions and 14 deletions

View File

@@ -5,7 +5,7 @@ import fs from "node:fs";
import fse from "fs-extra";
import { join, basename, dirname } from "node:path";
import { platform, what_platform } from "./platform/index.js";
import { isDevelopment, isInstallJava, readzipentry } from "./utils/utils.js";
import { type ForgeInfo, isDevelopment, isInstallJava, readzipentry } from "./utils/utils.js";
import fabric from "./ml_install/fabric.js";
import forge from "./ml_install/forge.js";
import neoforge from "./ml_install/neoforge.js";
@@ -39,7 +39,7 @@ if (!argv) {
function initdir() {
if (!fs.existsSync(unzip_path)) {
fse.ensureDirSync(join(unzip_path, "rubbish"));
fse.ensureDirSync(join(unzip_path, ".rubbish"));
}
}
@@ -88,12 +88,13 @@ async function main(modpack_path: string) {
const plat = platform(what_platform(dud_files));
const info = await plat.getinfo(pack_info);
await plat.downloadfile(pack_info, dirx);
await DeEarthMain(join(dirx, "mods"), join(unzip_path, "rubbish"));
await DeEarthMain(join(dirx, "mods"), join(unzip_path, ".rubbish"));
await install(info.loader, info.minecraft, info.loader_version, dirx);
fs.writeFileSync(
join(dirx, "eula.txt"),
"#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).\n#This serverpack created by DeEarthX(QQ_Group:559349662)\neula=true"
);
await garcol(dirx,{minecraft_verison: info.minecraft, forge_verison: info.loader_version}).catch((e)=>{});
LOGGER.info("DeEarthX已将服务端制作完成");
zipfile.close();
});
@@ -116,6 +117,9 @@ async function install(
break;
case "fabric-loader":
await fabric(minecraft, loaderver, path);
const com = "java -jar fabric-server-launch.jar"
fs.writeFileSync(join(path,'run.bat'),com)
fs.writeFileSync(join(path,'run.sh'),com)
break;
case "forge":
await forge(minecraft, loaderver, path);
@@ -126,6 +130,24 @@ async function install(
}
}
async function garcol(p:string,fi:ForgeInfo): Promise<void> {
return new Promise((resolve,reject)=>{
try{
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/`,'essential/']
for (let i=0;i<x.length;i++){
try{
fs.rmSync(join(p, x[i]),{recursive: true, force: true})
}catch(e){}
}
resolve()
}catch(err){
reject(err)
}
})
}
function getCurrnetDir() {
const url = new URL(".", import.meta.url);
return fileURLToPath(url);

View File

@@ -1,6 +1,7 @@
import cp from "child_process";
import fsExtra from "fs-extra";
import got from "got";
import { usemirror } from "../utils/utils.js";
export default async function install(
mcver: string,
fabricver: string,
@@ -8,12 +9,12 @@ export default async function install(
) {
const data = (
await got.get(
`https://maven.fabricmc.net/net/fabricmc/fabric-installer/1.0.1/fabric-installer-1.0.1.jar`
`https://maven.fabricmc.net/net/fabricmc/fabric-installer/1.0.3/fabric-installer-1.0.3.jar`
)
).rawBody;
fsExtra.outputFileSync(path+"/fabric-installer-1.0.1.jar", data);
fsExtra.outputFileSync(path+"/fabric-installer-1.0.3.jar", data);
cp.execSync(
`java -jar fabric-installer-1.0.1.jar server -mcver ${mcver} -loader ${fabricver}`,
`java -jar fabric-installer-1.0.3.jar server -mcver ${mcver} -loader ${fabricver}`,
{ cwd: path, stdio: "ignore" }
);
}

View File

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

View File

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

View File

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

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";
@@ -19,7 +20,7 @@ export async function DeEarthMain(modspath: string, movepath: any) {
}
LOGGER.info(`DeEarth V1.0.0`)
LOGGER.info(`如有无法筛选的mods请前往 https://dearth.0771010.xyz/ 提交未成功筛选的模组的modid`)
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod如rubbish中有请自行添加回去`)
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod.rubbish中有请自行添加回去`)
const resaddr = fs.readdirSync(modspath)
LOGGER.info(`获取目录列表,一共${resaddr.length}个jar文件。`)
const totalBar = multibar.create(resaddr.length, 0, { filename: '总文件数' })
@@ -136,8 +137,14 @@ 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){
if(zipinfo.modinfo.type === "forge"){
modid = zipinfo.modinfo.data.mods[0].modId
}else if(zipinfo.modinfo.type === "fabric"){
@@ -145,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)}`)
}
@@ -153,6 +160,8 @@ export async function DeEarth(modpath: string, movepath: string) {
try {
if (JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`)).isClient) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}else{
throw new Error("DeEarthPublic Not Found This Mod")
}
} catch (error) { //mods.toml或fabric.mod.json判断
try{
@@ -191,12 +200,14 @@ export async function DeEarth(modpath: string, movepath: string) {
}
}
}
}
function ZipInfo(modpath: string) {
interface ZipInfo {
mixins: { filename: string, info: string }[]
modinfo: {type:string,data:any};
}
try{
let zipinfo: ZipInfo = { mixins: [], modinfo: {type: "",data: {}} }
const zip = new AdmZip(modpath).getEntries();
for (let i = 0; i < zip.length; i++) {
@@ -212,6 +223,9 @@ function ZipInfo(modpath: string) {
}
}
return zipinfo;
}catch(error){
LOGGER.error(error)
}
}
async function FastGot(url: string) {
@@ -221,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源
//}

View File

@@ -10,6 +10,11 @@ import { URL, fileURLToPath } from "node:url";
import { LOGGER } from "./logger.js";
import { exec } from "node:child_process";
export interface ForgeInfo{
minecraft_verison: string,
forge_verison: string
}
export async function readzipentry(
zipfile: yauzl.ZipFile,
entry: yauzl.Entry
@@ -148,7 +153,11 @@ export async function xfastdownload(
path !== null &&
!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); //保存文件
}
},