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
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user