feat:UI及切换后端为http

This commit is contained in:
Tianpao
2025-09-14 21:20:39 +08:00
parent c61563c484
commit ffdff97b44
20 changed files with 1450 additions and 473 deletions

View File

@@ -0,0 +1,52 @@
import yauzl from "yauzl";
import Stream from "node:stream"
export interface IentryP extends yauzl.Entry {
openReadStream: Promise<Stream.Readable>;
}
export async function yauzl_promise(buffer: Buffer): Promise<IentryP[]>{
const zip = await (new Promise((resolve,reject)=>{
yauzl.fromBuffer(buffer,/*{lazyEntries:true},*/ (err, zipfile) => {
if (err){
reject(err);
return;
}
resolve(zipfile);
});
return;
}) as Promise<yauzl.ZipFile>);
return new Promise((resolve, reject) => {
const entries: IentryP[]= []
zip.on("entry", async (entry: yauzl.Entry) => {
const _entry = {
...entry,
getLastModDate: entry.getLastModDate,
isEncrypted: entry.isEncrypted,
isCompressed: entry.isCompressed,
openReadStream: _openReadStream(zip,entry)
}
entries.push(_entry)
if (zip.entryCount === entries.length){
zip.close();
resolve(entries);
}
});
zip.on("error",err=>{
reject(err);
})
});
}
async function _openReadStream(zip:yauzl.ZipFile,entry:yauzl.Entry): Promise<Stream.Readable>{
return new Promise((resolve,reject)=>{
zip.openReadStream(entry,(err,stream)=>{
if (err){
reject(err);
return;
}
resolve(stream);
})
})
}