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

+7 -10
View File
@@ -1,9 +1,10 @@
/* eslint-disable no-await-in-loop */
import os from 'os';
import path from 'path';
import { Readable } from 'stream';
import {
AdmZip, buildContent, Context, fs, Handler, PERM,
ProblemConfigFile, ProblemModel, ValidationError, yaml,
buildContent, Context, extractZip, fs, Handler, PERM,
ProblemConfigFile, ProblemModel, ValidationError, yaml, Zip,
} from 'hydrooj';
const tmpdir = path.join(os.tmpdir(), 'hydro', 'import-hoj');
@@ -11,15 +12,11 @@ fs.ensureDirSync(tmpdir);
class ImportHojHandler extends Handler {
async fromFile(domainId: string, zipfile: string) {
let zip: AdmZip;
try {
zip = new AdmZip(zipfile);
} catch (e) {
throw new ValidationError('zip', null, e.message);
}
const zip = new Zip.ZipReader(Readable.toWeb(fs.createReadStream(zipfile)));
const tmp = path.resolve(tmpdir, String.random(32));
await new Promise((resolve, reject) => {
zip.extractAllToAsync(tmp, true, false, (err) => (err ? reject(err) : resolve(null)));
await extractZip(zip, tmp, {
strip: true,
parseError: (e) => new ValidationError('zip', null, e.message),
});
let cnt = 0;
try {