feat:大部分功能完成

This commit is contained in:
Tianpao
2025-09-28 00:21:01 +08:00
parent b359fc881e
commit 5f16ee2bfa
22 changed files with 471 additions and 121 deletions

View File

@@ -3,6 +3,8 @@ import crypto from "node:crypto"
import { yauzl_promise } from "./yauzl.promise.js"
import got from "got"
import { Utils } from "./utils.js"
import pa from "node:path"
import WebSocket from "ws"
interface IMixins{
name: string
data: string
@@ -29,9 +31,9 @@ export class DeEarth{
modspath: string
file: IFile[]
utils: Utils
constructor(modspath:string) {
constructor(modspath:string,movepath:string) {
this.utils = new Utils();
this.movepath = "./.rubbish"
this.movepath = movepath
this.modspath = modspath
this.file = []
}
@@ -44,8 +46,10 @@ export class DeEarth{
const hash = await this.Check_Hashes()
const mixins = await this.Check_Mixins()
const result = [...new Set(hash.concat(mixins))]
console.log(result)
result.forEach(async e=>{
await fs.promises.rename(`${this.modspath}/${e}`,`${this.movepath}/${e}`)
await fs.promises.rename(`${e}`,`${this.movepath}/${e}`.replace(this.modspath,""))
//await fs.promises.rename(`${this.modspath}/${e}`,`${this.movepath}/${e}`)
})
}

View File

@@ -4,6 +4,8 @@ import got from "got";
import pRetry from "p-retry";
import fs from "node:fs";
import fse from "fs-extra";
import { WebSocket } from "ws";
import { ExecOptions, exec} from "node:child_process";
export class Utils {
public modrinth_url: string;
@@ -47,6 +49,19 @@ export function version_compare(v1: string, v2: string) {
return 0;
}
export function execPromise(cmd:string,options:ExecOptions){
return new Promise((resolve,reject)=>{
exec(cmd,options,(err,stdout,stderr)=>{
if(err){
reject(err)
return;
}
}).on('exit',(code)=>{
resolve(code)
})
})
}
export async function fastdownload(data: [string, string]) {
return await pMap(
[data],
@@ -95,6 +110,46 @@ export async function fastdownload(data: [string, string]) {
);
}
export async function Wfastdownload(data: [string, string],ws:WebSocket) {
let index = 1;
return await pMap(
data,
async (e:any) => {
try {
await pRetry(
async () => {
if (!fs.existsSync(e[1])) {
await got
.get(e[0], {
responseType: "buffer",
headers: {
"user-agent": "DeEarthX",
},
})
.then((res) => {
fse.outputFileSync(e[1], res.rawBody);
});
}
ws.send(JSON.stringify({
status:"downloading",
result:{
total:data.length,
index:index,
name:e[1]
}
}))
index++
},
{ retries: 3 }
);
} catch (e) {
//LOGGER.error({ err: e });
}
},
{ concurrency: 16 }
);
}
export async function xfastdownload(data: [string, string][]) {
return await pMap(
data,

View File

@@ -4,6 +4,7 @@ import Stream from "node:stream"
export interface IentryP extends yauzl.Entry {
openReadStream: Promise<Stream.Readable>;
ReadEntry: Promise<Buffer>;
ReadEntrySync: Buffer;
}
export async function yauzl_promise(buffer: Buffer): Promise<IentryP[]>{
@@ -27,7 +28,8 @@ export async function yauzl_promise(buffer: Buffer): Promise<IentryP[]>{
isEncrypted: entry.isEncrypted,
isCompressed: entry.isCompressed,
openReadStream: _openReadStream(zip,entry),
ReadEntry: _ReadEntry(zip,entry)
ReadEntry: _ReadEntry(zip,entry),
ReadEntrySync: (await _ReadEntry(zip,entry))
}
entries.push(_entry)
if (zip.entryCount === entries.length){