core: change to @zip.js/zip.js

This commit is contained in:
undefined committed 2025-04-14 16:22:54 +08:00
1 parent d46de63264
commit e31b84d29e
17 files changed
+129 -108

No files matched your search

+1 -2
View File
@@ -8,7 +8,7 @@
"dependencies": {
"@hydrooj/common": "workspace:^",
"@hydrooj/utils": "workspace:^",
"adm-zip": "0.5.16",
"@zip.js/zip.js": "^2.7.60",
"cac": "^6.7.14",
"p-queue": "^8.1.0",
"schemastery": "^3.16.1",
@@ -20,7 +20,6 @@
"preferUnplugged": true,
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@types/adm-zip": "^0.5.7",
"@types/shell-quote": "^1.7.5",
"@types/ws": "^8.18.1"
}
+13 -19
View File
@@ -1,11 +1,15 @@
/* eslint-disable no-await-in-loop */
import { createReadStream } from 'fs';
import path from 'path';
import AdmZip from 'adm-zip';
import { Readable } from 'stream';
import { ZipReader } from '@zip.js/zip.js';
import PQueue from 'p-queue';
import superagent from 'superagent';
import WebSocket from 'ws';
import { JudgeResultBody, parseLang, STATUS } from '@hydrooj/common';
import { findFileSync, fs, noop } from '@hydrooj/utils';
import {
extractZip, findFileSync, fs, noop,
} from '@hydrooj/utils';
import { getConfig } from '../config';
import { FormatError, SystemError } from '../error';
import { Session } from '../interface';
@@ -151,16 +155,11 @@ export default class VJ4 implements Session {
fs.createWriteStream(tmpFilePath),
);
fs.ensureDirSync(path.dirname(savePath));
const zip = new AdmZip(tmpFilePath);
const entries = zip.getEntries();
const zip = new ZipReader(Readable.toWeb(createReadStream(tmpFilePath)));
const entries = await zip.getEntries();
if (entries.length > 512) throw new FormatError('Too many files');
if (Math.sum(entries.map((i) => i.header.size)) > 256 * 1024 * 1024) throw new FormatError('File too large');
await new Promise((resolve, reject) => {
zip.extractAllToAsync(savePath, true, false, (e) => {
if (e) reject(e);
else resolve(null);
});
});
if (Math.sum(entries.map((i) => i.uncompressedSize)) > 256 * 1024 * 1024) throw new FormatError('File too large');
await extractZip(entries, savePath, { strip: true });
await fs.unlink(tmpFilePath);
await this.processData(savePath).catch(noop);
} catch (e) {
@@ -177,15 +176,10 @@ export default class VJ4 implements Session {
const w = fs.createWriteStream(tmpFilePath);
await pipeRequest(this.get(`records/${rid}/data`), w);
fs.ensureDirSync(path.dirname(savePath));
const zip = new AdmZip(tmpFilePath);
const entries = zip.getEntries();
const zip = new ZipReader(Readable.toWeb(createReadStream(tmpFilePath)));
const entries = await zip.getEntries();
if (entries.length > 512) throw new FormatError('Too many files');
await new Promise((resolve, reject) => {
zip.extractAllToAsync(savePath, true, false, (e) => {
if (e) reject(e);
else resolve(null);
});
});
await extractZip(entries, savePath, { strip: true });
await fs.unlink(tmpFilePath);
await this.processData(savePath);
return savePath;