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

View File

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

View File

@@ -1,7 +1,7 @@
/* Power by.Tianpao /* Power by.Tianpao
* 本工具可能会判断失误,但也能为您节省不少时间! * 本工具可能会判断失误,但也能为您节省不少时间!
* DeEarth V2 From StarNet.X * DeEarth V2 From StarNet.X
* Writing in 03.29.2025(latest) * Writing in 07.10.2025(latest)
* ©2024-2025 * ©2024-2025
*/ */
import AdmZip from "adm-zip"; import AdmZip from "adm-zip";
@@ -35,24 +35,25 @@ fs.mkdirSync(movepath)
} }
export async function DeEarth(modpath: string, movepath: string) { export async function DeEarth(modpath: string, movepath: string) {
try{
const zip = new AdmZip(modpath).getEntries(); const zip = new AdmZip(modpath).getEntries();
//for (let i = 0; i < zip.length; i++) { //for (let i = 0; i < zip.length; i++) {
//const e = zip[i] //const e = zip[i]
try { //Modrinth try { //Modrinth
for (let i = 0; i < zip.length; i++) { for (let i = 0; i < zip.length; i++) {
const e = zip[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 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 = 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}`)) 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)}`) fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
} }
} else if (e.entryName == "fabric.mod.json") { //Fabric } else if (e.entryName == "fabric.mod.json") { //Fabric
const modid = JSON.parse(e.getData().toString('utf-8')).id 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 = 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}`)) 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)}`) fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
} }
} }
@@ -61,7 +62,7 @@ export async function DeEarth(modpath: string, movepath: string) {
try{//DeEarthPublic try{//DeEarthPublic
for (let i = 0; i < zip.length; i++) { for (let i = 0; i < zip.length; i++) {
const e = zip[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 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}`)) const body = JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`))
if (body.isClient) { if (body.isClient) {
@@ -79,7 +80,7 @@ export async function DeEarth(modpath: string, movepath: string) {
for (let i = 0; i < zip.length; i++) { for (let i = 0; i < zip.length; i++) {
const e = zip[i] const e = zip[i]
try { 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 tr = toml.parse(e.getData().toString('utf-8'))
const mcside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "minecraft").side const mcside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "minecraft").side
if (mcside == "CLIENT"){ //从Minecraft判断 if (mcside == "CLIENT"){ //从Minecraft判断
@@ -89,6 +90,10 @@ export async function DeEarth(modpath: string, movepath: string) {
if (forgeside == "CLIENT") { //从Forge判断 if (forgeside == "CLIENT") { //从Forge判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`) 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 } else if (e.entryName == "fabric.mod.json") { //Fabric
const fmj = JSON.parse(e.getData().toString('utf-8')).environment const fmj = JSON.parse(e.getData().toString('utf-8')).environment
if (fmj == "client") { if (fmj == "client") {
@@ -99,15 +104,15 @@ export async function DeEarth(modpath: string, movepath: string) {
for (let i = 0; i < zip.length; i++) { for (let i = 0; i < zip.length; i++) {
const e = zip[i] const e = zip[i]
try { 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) LOGGER.info(e.entryName)
const resx = JSON.parse(e.getData().toString('utf-8')) const resx = JSON.parse(e.getData().toString('utf-8'))
if (e.entryName.includes("common.mixins.json")) { //第一步从common mixins文件判断判断失败后再使用modid.mixins.json进行判断 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)}`) fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
} }
} else { } 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)}`) 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) { async function FastGot(url: string) {
@@ -159,6 +167,18 @@ const multibar = new MultiBar({
notTTYSchedule: 10*1000, 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) { 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})))$/; 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); return chinaRegex.test(ipAddress);

View File

@@ -1,22 +1,25 @@
import pMap from "p-map"; import pMap from "p-map";
import pRetry from "p-retry"; import pRetry from "p-retry";
import fs from "node:fs" import fs from "node:fs";
import fse from "fs-extra" import fse from "fs-extra";
import yauzl from "yauzl"; import yauzl from "yauzl";
import got from "got"; import got from "got";
import env from "dotenv" import env from "dotenv";
import { MultiBar } from "cli-progress"; import { MultiBar } from "cli-progress";
import {URL, fileURLToPath } from "node:url"; import { URL, fileURLToPath } from "node:url";
import { LOGGER } from "./logger.js"; 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>[] = []; const data: Buffer<ArrayBufferLike>[] = [];
return await new Promise((reslove, reject) => { return await new Promise((reslove, reject) => {
zipfile.openReadStream(entry, (err, e) => { zipfile.openReadStream(entry, (err, e) => {
e.on("data", (chunk: Buffer) => { e.on("data", (chunk: Buffer) => {
data.push(chunk); data.push(chunk);
}).on("end", () => { }).on("end", () => {
if (data.length !== 0&&typeof data !== "string"){ if (data.length !== 0 && typeof data !== "string") {
reslove(Buffer.concat(data).toString()); reslove(Buffer.concat(data).toString());
} }
}); });
@@ -24,76 +27,112 @@ export async function readzipentry(zipfile: yauzl.ZipFile, entry: yauzl.Entry):P
}); });
} }
export async function fastdownload(data:[string,string]){ export async function fastdownload(data: [string, string]) {
const multibar = new MultiBar({ const multibar = new MultiBar({
format: ' {bar} | {filename} | {value}/{total}', format: " {bar} | {filename} | {value}/{total}",
noTTYOutput: true, noTTYOutput: true,
notTTYSchedule: 10*1000, 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}',
noTTYOutput: true,
notTTYSchedule: 10*1000,
}); });
const totalBar = multibar.create(data.length, 0, { filename: '总文件数' }); const totalBar = multibar.create(data.length, 0, { filename: "总文件数" });
return await pMap(data, async (e) => { return await pMap(
const bar = multibar.create(Number(e[2]), 0, { filename: e[1] }); 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 { try {
await pRetry(async () => { await pRetry(
if (!fse.existsSync(e[1])) { async () => {
await got.get(e[0], { if (!fs.existsSync(e[1])) {
await got
.get(e[0], {
responseType: "buffer", responseType: "buffer",
}).on('downloadProgress', (progress) => { headers: {
"user-agent": "DeEarthX",
},
})
.on("downloadProgress", (progress) => {
bar.update(progress.transferred); bar.update(progress.transferred);
}).then((res) => { })
.then((res) => {
fse.outputFileSync(e[1], res.rawBody); fse.outputFileSync(e[1], res.rawBody);
}); });
} }
}, { retries: 3 }); },
} { retries: 3 }
catch (e) { );
} catch (e) {
LOGGER.error({ err: e }); LOGGER.error({ err: e });
} } finally {
finally {
bar.stop(); bar.stop();
totalBar.increment(); totalBar.increment();
multibar.remove(bar); 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( export async function xfastdownload(
url: string, url: string,
path: string, path: string,
concurrency: number = 1 concurrency: number = 1
) { ) {
let e = []; let e = [];
e.push([url, path]); e.push([url, path]);
await pMap( await pMap(
@@ -124,19 +163,19 @@ export async function xfastdownload(
concurrency: concurrency, concurrency: concurrency,
} }
); );
} }
export const usemirror = (()=>{ export const usemirror = (() => {
env.config({debug:false}) env.config({ debug: false });
const mirror = process.env.MIRROR const mirror = process.env.MIRROR;
if(mirror){ if (mirror) {
return false return false;
}else{ } else {
return true return true;
} }
})() })();
export const isDevelopment = (()=>{ export const isDevelopment = (() => {
env.config() env.config();
return process.env.DEVELOPMENT return process.env.DEVELOPMENT;
})() })();