Compare commits
6 Commits
1e35fac53b
...
40492b8bd0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40492b8bd0 | ||
|
|
bb860b2c4a | ||
|
|
9dcc4e6c83 | ||
|
|
cfa97c8715 | ||
|
|
0acd64ae86 | ||
|
|
2f518e4487 |
19
src/main.ts
19
src/main.ts
@@ -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;
|
||||
dud_files.push(name);
|
||||
if (name.endsWith(".json")) {
|
||||
} else if (name.endsWith(".json")||name.includes("mcbbs.packmeta")) {
|
||||
dud_files.push(name);
|
||||
//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();
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
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 { 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) => {
|
||||
e.on("data", (chunk: Buffer) => {
|
||||
data.push(chunk);
|
||||
}).on("end", () => {
|
||||
if (data.length !== 0&&typeof data !== "string"){
|
||||
if (data.length !== 0 && typeof data !== "string") {
|
||||
reslove(Buffer.concat(data).toString());
|
||||
}
|
||||
});
|
||||
@@ -24,119 +27,155 @@ 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({
|
||||
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)
|
||||
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: { "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 (!fs.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})
|
||||
},
|
||||
{ concurrency: 16 }
|
||||
);
|
||||
}
|
||||
|
||||
export async function mr_fastdownload(data:[string,string,string]){
|
||||
export async function mr_fastdownload(data: [string, string, string]) {
|
||||
const multibar = new MultiBar({
|
||||
format: ' {bar} | {filename} | {value}/{total}',
|
||||
noTTYOutput: true,
|
||||
notTTYSchedule: 10*1000,
|
||||
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 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",
|
||||
}).on('downloadProgress', (progress) => {
|
||||
bar.update(progress.transferred);
|
||||
}).then((res) => {
|
||||
fse.outputFileSync(e[1], res.rawBody);
|
||||
});
|
||||
}
|
||||
}, { retries: 3 });
|
||||
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);
|
||||
}
|
||||
catch (e) {
|
||||
LOGGER.error({ err: e });
|
||||
}
|
||||
finally {
|
||||
bar.stop();
|
||||
totalBar.increment();
|
||||
multibar.remove(bar);
|
||||
}
|
||||
}, { concurrency: 16 });
|
||||
},
|
||||
{ concurrency: 16 }
|
||||
);
|
||||
}
|
||||
|
||||
export async function xfastdownload(
|
||||
url: string,
|
||||
path: string,
|
||||
concurrency: number = 1
|
||||
) {
|
||||
let e = [];
|
||||
e.push([url, path]);
|
||||
await pMap(
|
||||
e,
|
||||
async (e) => {
|
||||
try {
|
||||
return await pRetry(
|
||||
async () => {
|
||||
if (
|
||||
url !== null &&
|
||||
url !== "" &&
|
||||
path !== null &&
|
||||
!fs.existsSync(e[1])
|
||||
) {
|
||||
const res = (await got.get(e[0])).rawBody; //下载文件
|
||||
await fse.outputFile(e[1], res); //保存文件
|
||||
}
|
||||
},
|
||||
{
|
||||
retries: 2,
|
||||
url: string,
|
||||
path: string,
|
||||
concurrency: number = 1
|
||||
) {
|
||||
let e = [];
|
||||
e.push([url, path]);
|
||||
await pMap(
|
||||
e,
|
||||
async (e) => {
|
||||
try {
|
||||
return await pRetry(
|
||||
async () => {
|
||||
if (
|
||||
url !== null &&
|
||||
url !== "" &&
|
||||
path !== null &&
|
||||
!fs.existsSync(e[1])
|
||||
) {
|
||||
const res = (await got.get(e[0])).rawBody; //下载文件
|
||||
await fse.outputFile(e[1], res); //保存文件
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
LOGGER.error({ err: error });
|
||||
}
|
||||
},
|
||||
{
|
||||
concurrency: concurrency,
|
||||
},
|
||||
{
|
||||
retries: 2,
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
LOGGER.error({ err: error });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export const usemirror = (()=>{
|
||||
env.config({debug:false})
|
||||
const mirror = process.env.MIRROR
|
||||
if(mirror){
|
||||
return false
|
||||
}else{
|
||||
return true
|
||||
},
|
||||
{
|
||||
concurrency: concurrency,
|
||||
}
|
||||
})()
|
||||
);
|
||||
}
|
||||
|
||||
export const isDevelopment = (()=>{
|
||||
env.config()
|
||||
return process.env.DEVELOPMENT
|
||||
})()
|
||||
export const usemirror = (() => {
|
||||
env.config({ debug: false });
|
||||
const mirror = process.env.MIRROR;
|
||||
if (mirror) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
})();
|
||||
|
||||
export const isDevelopment = (() => {
|
||||
env.config();
|
||||
return process.env.DEVELOPMENT;
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user