mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: change to @zip.js/zip.js
This commit is contained in:
17 files changed
+129
-108
No files matched your search
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user