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) => {
|
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();
|
||||||
|
|||||||
@@ -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
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,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({
|
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: '总文件数'})
|
const totalBar = multibar.create(data.length, 0, { filename: "总文件数" });
|
||||||
return await pMap(data,async(e)=>{
|
return await pMap(
|
||||||
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}})()
|
data,
|
||||||
const bar = multibar.create(size, 0, {filename: e[1]})
|
async (e) => {
|
||||||
try{
|
const size: number = await (async () => {
|
||||||
await pRetry(async()=>{
|
const head = (
|
||||||
if(!fs.existsSync(e[1])){
|
await got.head(
|
||||||
await got.get(e[0],{
|
e[0] /*.replace("https://mod.mcimirror.top","https://edge.forgecdn.net")*/,
|
||||||
responseType:"buffer",
|
{ headers: { "user-agent": "DeEarthX" } }
|
||||||
}).on('downloadProgress',(progress)=>{
|
)
|
||||||
bar.update(progress.transferred)
|
).headers["content-length"];
|
||||||
}).then((res)=>{
|
if (head) {
|
||||||
fse.outputFileSync(e[1],res.rawBody)
|
return Number(head);
|
||||||
})
|
} else {
|
||||||
}
|
return 0;
|
||||||
},{retries:3})
|
}
|
||||||
}catch(e){
|
})();
|
||||||
LOGGER.error({err:e})
|
const bar = multibar.create(size, 0, { filename: e[1] });
|
||||||
}finally{
|
try {
|
||||||
bar.stop()
|
await pRetry(
|
||||||
totalBar.increment()
|
async () => {
|
||||||
multibar.remove(bar)
|
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({
|
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: '总文件数' });
|
const totalBar = multibar.create(data.length, 0, { filename: "总文件数" });
|
||||||
return await pMap(data, async (e) => {
|
return await pMap(
|
||||||
|
data,
|
||||||
|
async (e) => {
|
||||||
const bar = multibar.create(Number(e[2]), 0, { filename: e[1] });
|
const bar = multibar.create(Number(e[2]), 0, { filename: e[1] });
|
||||||
try {
|
try {
|
||||||
await pRetry(async () => {
|
await pRetry(
|
||||||
if (!fse.existsSync(e[1])) {
|
async () => {
|
||||||
await got.get(e[0], {
|
if (!fse.existsSync(e[1])) {
|
||||||
responseType: "buffer",
|
await got
|
||||||
}).on('downloadProgress', (progress) => {
|
.get(e[0], {
|
||||||
bar.update(progress.transferred);
|
responseType: "buffer",
|
||||||
}).then((res) => {
|
headers: {
|
||||||
fse.outputFileSync(e[1], res.rawBody);
|
"user-agent": "DeEarthX",
|
||||||
});
|
},
|
||||||
}
|
})
|
||||||
}, { retries: 3 });
|
.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 });
|
{ concurrency: 16 }
|
||||||
}
|
);
|
||||||
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(
|
||||||
e,
|
e,
|
||||||
async (e) => {
|
async (e) => {
|
||||||
try {
|
try {
|
||||||
return await pRetry(
|
return await pRetry(
|
||||||
async () => {
|
async () => {
|
||||||
if (
|
if (
|
||||||
url !== null &&
|
url !== null &&
|
||||||
url !== "" &&
|
url !== "" &&
|
||||||
path !== null &&
|
path !== null &&
|
||||||
!fs.existsSync(e[1])
|
!fs.existsSync(e[1])
|
||||||
) {
|
) {
|
||||||
const res = (await got.get(e[0])).rawBody; //下载文件
|
const res = (await got.get(e[0])).rawBody; //下载文件
|
||||||
await fse.outputFile(e[1], res); //保存文件
|
await fse.outputFile(e[1], res); //保存文件
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
retries: 2,
|
|
||||||
}
|
}
|
||||||
);
|
},
|
||||||
} catch (error) {
|
{
|
||||||
LOGGER.error({ err: error });
|
retries: 2,
|
||||||
}
|
}
|
||||||
},
|
);
|
||||||
{
|
} catch (error) {
|
||||||
concurrency: concurrency,
|
LOGGER.error({ err: error });
|
||||||
}
|
}
|
||||||
);
|
},
|
||||||
}
|
{
|
||||||
|
concurrency: concurrency,
|
||||||
export const usemirror = (()=>{
|
|
||||||
env.config({debug:false})
|
|
||||||
const mirror = process.env.MIRROR
|
|
||||||
if(mirror){
|
|
||||||
return false
|
|
||||||
}else{
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
})()
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export const isDevelopment = (()=>{
|
export const usemirror = (() => {
|
||||||
env.config()
|
env.config({ debug: false });
|
||||||
return process.env.DEVELOPMENT
|
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