Compare commits

..

6 Commits

Author SHA1 Message Date
Tianpao
40492b8bd0 fix:DeEarth unzip出错时无法处理 refactor:支持从MCIM获取head 2025-07-10 13:46:05 +08:00
Tianpao
bb860b2c4a feat:同步DeEarth上游分支 2025-07-10 09:48:56 +08:00
Tianpao
9dcc4e6c83 fix:DeEarth无法识别NeoForge 2025-07-09 21:47:01 +08:00
Tianpao
cfa97c8715 fix:neoforge无法安装 2025-07-09 21:44:04 +08:00
Tianpao
0acd64ae86 fix:neoforge无法使用 2025-07-09 20:44:54 +08:00
Tianpao
2f518e4487 refactor:优化 2025-07-09 19:15:59 +08:00
4 changed files with 187 additions and 131 deletions

View File

@@ -54,12 +54,13 @@ async function main(modpack_path: string) {
yauzl.open(modpack_path, { lazyEntries: true }, (err, zipfile) => {
zipfile.readEntry(); //首次读取
zipfile.on("entry", async (entry) => {
if (/\/$/.test(entry.fileName)) {
} else if (entry.fileName.includes("overrides/")) {
const name: string = entry.fileName;
if (/\/$/.test(name)) {
} else if (name.includes("overrides/")) {
const zipfilex = join(
unzip_path,
zipname,
entry.fileName.replace("overrides/", "")
name.replace("overrides/", "")
);
if (!fs.existsSync(zipfilex)) {
zipfile.openReadStream(entry, (err, stream) => {
@@ -69,18 +70,14 @@ async function main(modpack_path: string) {
console.log(zipfilex);
stream.pipe(fse.createWriteStream(zipfilex));
});
//console.log(entry.fileName)
}
} else {
const name: string = entry.fileName;
} else if (name.endsWith(".json")||name.includes("mcbbs.packmeta")) {
dud_files.push(name);
if (name.endsWith(".json")) {
//console.log((await readzipentry(zipfile, entry)))
pack_info = JSON.parse(
(await readzipentry(zipfile, entry)).toString()
);
}
}
zipfile.readEntry();
});
zipfile.on("end", async () => {
@@ -92,8 +89,8 @@ async function main(modpack_path: string) {
await DeEarthMain(join(dirx, "mods"), join(unzip_path, "rubbish"));
await install(info.loader, info.minecraft, info.loader_version, dirx);
fs.writeFileSync(
join(dirx, "instance.zip"),
"#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\neula=true"
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"
);
LOGGER.info("DeEarthX已将服务端制作完成");
zipfile.close();

View File

@@ -19,7 +19,7 @@ export default async function install(
neoforge: string,
path: string
) {
const mcinfo = (await gotx
const mcinfo = (await got
.get(`version/${minecraft}/json`)
.json()) as mcinfoX; //获取Minecraft版本JSON
const installer = (
@@ -35,7 +35,7 @@ export default async function install(
//下载依赖1
const t = fvdata[c].downloads.artifact;
await xfastdownload(
`maven${new URL(t.url).pathname}`,
`https://bmclapi2.bangbang93.com/maven${new URL(t.url).pathname.replace("/releases","")}`,
`${path}/libraries/${t.path}`,
16
);
@@ -47,7 +47,7 @@ export default async function install(
//下载依赖2
const t = fvdata[c].downloads.artifact;
await xfastdownload(
`maven${new URL(t.url).pathname}`,
`https://bmclapi2.bangbang93.com/maven${new URL(t.url).pathname.replace("/releases","")}`,
`${path}/libraries/${t.path}`,
16
);
@@ -57,13 +57,13 @@ export default async function install(
for (let d = 0; d < mcinfo.libraries.length; d++) {
const g = mcinfo.libraries[d].downloads.artifact;
await xfastdownload(
`maven${new URL(g.url).pathname}`,
`https://bmclapi2.bangbang93.com/maven${new URL(g.url).pathname}`,
`${path}/libraries/${g.path}`,
16
);
}
await xfastdownload(
`version/${minecraft}/server`,
`https://bmclapi2.bangbang93.com/version/${minecraft}/server`,
`${path}/libraries/net/minecraft/server/${minecraft}/server-${minecraft}.jar`,
1
);

View File

@@ -1,7 +1,7 @@
/* Power by.Tianpao
* 本工具可能会判断失误,但也能为您节省不少时间!
* DeEarth V2 From StarNet.X
* Writing in 03.29.2025(latest)
* Writing in 07.10.2025(latest)
* ©2024-2025
*/
import AdmZip from "adm-zip";
@@ -35,24 +35,25 @@ fs.mkdirSync(movepath)
}
export async function DeEarth(modpath: string, movepath: string) {
try{
const zip = new AdmZip(modpath).getEntries();
//for (let i = 0; i < zip.length; i++) {
//const e = zip[i]
try { //Modrinth
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
if (e.entryName == "META-INF/mods.toml") { //Forge,NeoForge
if (isForge(e.entryName)) { //Forge,NeoForge
const modid = toml.parse(e.getData().toString('utf-8')).mods[0].modId
//const body = await got.get(`https://api.modrinth.com/v2/project/${modid}`, { headers: { "User-Agent": "DeEarth" } }).json()
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
if (body.client_side == "required" && body.server_side == "unsupported") {
if (body.client_side == "required" && body.server_side !== "required") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else if (e.entryName == "fabric.mod.json") { //Fabric
const modid = JSON.parse(e.getData().toString('utf-8')).id
//const body = await got.get(`https://api.modrinth.com/v2/project/${modid}`, { headers: { "User-Agent": "DeEarth" } }).json()
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
if (body.client_side == "required" && body.server_side == "unsupported") {
if (body.client_side == "required" && body.server_side !== "required") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
@@ -61,7 +62,7 @@ export async function DeEarth(modpath: string, movepath: string) {
try{//DeEarthPublic
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
if (e.entryName == "META-INF/mods.toml") { //Forge,Neoforge
if (isForge(e.entryName)) { //Forge,Neoforge
const modid = toml.parse(e.getData().toString('utf-8')).mods[0].modId
const body = JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`))
if (body.isClient) {
@@ -79,7 +80,7 @@ export async function DeEarth(modpath: string, movepath: string) {
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
try {
if (e.entryName == "META-INF/mods.toml") { //Forge,Neoforge
if (isForge(e.entryName)) { //Forge,Neoforge
const tr = toml.parse(e.getData().toString('utf-8'))
const mcside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "minecraft").side
if (mcside == "CLIENT"){ //从Minecraft判断
@@ -89,6 +90,10 @@ export async function DeEarth(modpath: string, movepath: string) {
if (forgeside == "CLIENT") { //从Forge判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
const neoside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "neoforge").side
if (neoside == "CLIENT") { //从NeoForge判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else if (e.entryName == "fabric.mod.json") { //Fabric
const fmj = JSON.parse(e.getData().toString('utf-8')).environment
if (fmj == "client") {
@@ -99,15 +104,15 @@ export async function DeEarth(modpath: string, movepath: string) {
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
try {
if (!e.entryName.includes("/") && e.entryName.endsWith(".json") && !e.entryName.endsWith("refmap.json") && !e.entryName.endsWith("mod.json")) {
if (isMixinFile(e.entryName)) {
LOGGER.info(e.entryName)
const resx = JSON.parse(e.getData().toString('utf-8'))
if (e.entryName.includes("common.mixins.json")) { //第一步从common mixins文件判断判断失败后再使用modid.mixins.json进行判断
if (resx.mixins == null || Object.keys(resx.mixins).length == 0 && Object.keys(resx.client).length !== 0) {
if (isMixin(resx)) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else {
if (resx.mixins == null || Object.keys(resx.mixins).length == 0 && Object.keys(resx.client).length !== 0) {
if (isMixin(resx)) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
@@ -122,6 +127,9 @@ export async function DeEarth(modpath: string, movepath: string) {
}
}
}
}catch(error){
LOGGER.error("DeEarth: "+error)
}
}
async function FastGot(url: string) {
@@ -159,6 +167,18 @@ const multibar = new MultiBar({
notTTYSchedule: 10*1000,
})
function isMixin(resx: { mixins: {} | null; client: {}; }){
return resx.mixins == null || Object.keys(resx.mixins).length == 0 && Object.keys(resx.client).length !== 0
}
function isForge(name:string):boolean{
return name.includes("mods.toml")||name.includes("META-INF")
}
function isMixinFile(name:string):boolean{
return !name.includes("/") && name.endsWith(".json") && !name.endsWith("refmap.json") && !name.endsWith("mod.json")
}
function isChinaIpAddress(ipAddress: string) {
const chinaRegex = /^((?:(?:1(?:0|1|2[0-7]|[3-9][0-9])|2(?:[0-4][0-9]|5[0-5])|[3-9][0-9]{2})\.){3}(?:(?:1(?:0|1|2[0-7]|[3-9][0-9])|2(?:[0-4][0-9]|5[0-5])|[3-9][0-9]{2})))$/;
return chinaRegex.test(ipAddress);

View File

@@ -1,15 +1,18 @@
import pMap from "p-map";
import pRetry from "p-retry";
import fs from "node:fs"
import fse from "fs-extra"
import fs from "node:fs";
import fse from "fs-extra";
import yauzl from "yauzl";
import got from "got";
import env from "dotenv"
import env from "dotenv";
import { MultiBar } from "cli-progress";
import { URL, fileURLToPath } from "node:url";
import { LOGGER } from "./logger.js";
export async function readzipentry(zipfile: yauzl.ZipFile, entry: yauzl.Entry):Promise<string> {
export async function readzipentry(
zipfile: yauzl.ZipFile,
entry: yauzl.Entry
): Promise<string> {
const data: Buffer<ArrayBufferLike>[] = [];
return await new Promise((reslove, reject) => {
zipfile.openReadStream(entry, (err, e) => {
@@ -26,67 +29,103 @@ export async function readzipentry(zipfile: yauzl.ZipFile, entry: yauzl.Entry):P
export async function fastdownload(data: [string, string]) {
const multibar = new MultiBar({
format: ' {bar} | {filename} | {value}/{total}',
noTTYOutput: true,
notTTYSchedule: 10*1000,
})
const totalBar = multibar.create(data.length, 0, {filename: '总文件数'})
return await pMap(data,async(e)=>{
const size:number = await (async()=>{const head = (await got.head(e[0].replace("https://mod.mcimirror.top","https://edge.forgecdn.net"))).headers['content-length'];if(head){return Number(head)}else{return 0}})()
const bar = multibar.create(size, 0, {filename: e[1]})
try{
await pRetry(async()=>{
if(!fs.existsSync(e[1])){
await got.get(e[0],{
responseType:"buffer",
}).on('downloadProgress',(progress)=>{
bar.update(progress.transferred)
}).then((res)=>{
fse.outputFileSync(e[1],res.rawBody)
})
}
},{retries:3})
}catch(e){
LOGGER.error({err:e})
}finally{
bar.stop()
totalBar.increment()
multibar.remove(bar)
}
},{concurrency:16})
}
export async function mr_fastdownload(data:[string,string,string]){
const multibar = new MultiBar({
format: ' {bar} | {filename} | {value}/{total}',
format: " {bar} | {filename} | {value}/{total}",
noTTYOutput: true,
notTTYSchedule: 10 * 1000,
});
const totalBar = multibar.create(data.length, 0, { filename: '总文件数' });
return await pMap(data, async (e) => {
const bar = multibar.create(Number(e[2]), 0, { filename: e[1] });
const totalBar = multibar.create(data.length, 0, { filename: "总文件数" });
return await pMap(
data,
async (e) => {
const size: number = await (async () => {
const head = (
await got.head(
e[0] /*.replace("https://mod.mcimirror.top","https://edge.forgecdn.net")*/,
{ headers: { "user-agent": "DeEarthX" } }
)
).headers["content-length"];
if (head) {
return Number(head);
} else {
return 0;
}
})();
const bar = multibar.create(size, 0, { filename: e[1] });
try {
await pRetry(async () => {
if (!fse.existsSync(e[1])) {
await got.get(e[0], {
await pRetry(
async () => {
if (!fs.existsSync(e[1])) {
await got
.get(e[0], {
responseType: "buffer",
}).on('downloadProgress', (progress) => {
headers: {
"user-agent": "DeEarthX",
},
})
.on("downloadProgress", (progress) => {
bar.update(progress.transferred);
}).then((res) => {
})
.then((res) => {
fse.outputFileSync(e[1], res.rawBody);
});
}
}, { retries: 3 });
}
catch (e) {
},
{ retries: 3 }
);
} catch (e) {
LOGGER.error({ err: e });
}
finally {
} finally {
bar.stop();
totalBar.increment();
multibar.remove(bar);
}
}, { concurrency: 16 });
},
{ concurrency: 16 }
);
}
export async function mr_fastdownload(data: [string, string, string]) {
const multibar = new MultiBar({
format: " {bar} | {filename} | {value}/{total}",
noTTYOutput: true,
notTTYSchedule: 10 * 1000,
});
const totalBar = multibar.create(data.length, 0, { filename: "总文件数" });
return await pMap(
data,
async (e) => {
const bar = multibar.create(Number(e[2]), 0, { filename: e[1] });
try {
await pRetry(
async () => {
if (!fse.existsSync(e[1])) {
await got
.get(e[0], {
responseType: "buffer",
headers: {
"user-agent": "DeEarthX",
},
})
.on("downloadProgress", (progress) => {
bar.update(progress.transferred);
})
.then((res) => {
fse.outputFileSync(e[1], res.rawBody);
});
}
},
{ retries: 3 }
);
} catch (e) {
LOGGER.error({ err: e });
} finally {
bar.stop();
totalBar.increment();
multibar.remove(bar);
}
},
{ concurrency: 16 }
);
}
export async function xfastdownload(
@@ -127,16 +166,16 @@ export async function xfastdownload(
}
export const usemirror = (() => {
env.config({debug:false})
const mirror = process.env.MIRROR
env.config({ debug: false });
const mirror = process.env.MIRROR;
if (mirror) {
return false
return false;
} else {
return true
return true;
}
})()
})();
export const isDevelopment = (() => {
env.config()
return process.env.DEVELOPMENT
})()
env.config();
return process.env.DEVELOPMENT;
})();