feat:同步DeEarth上游分支

This commit is contained in:
Tianpao
2025-07-10 09:48:56 +08:00
parent 9dcc4e6c83
commit bb860b2c4a

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";
@@ -45,14 +45,14 @@ export async function DeEarth(modpath: string, movepath: string) {
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)}`)
}
}
@@ -89,6 +89,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 +103,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)}`)
}
}
@@ -159,10 +163,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);