mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: import: handle error message for invalid zip
This commit is contained in:
1 parent
cb424c9cac
commit
895d50530a
4 files changed
+24
-4
No files matched your search
@@ -111,7 +111,12 @@ class FpsProblemImportHandler extends Handler {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof FileTooLargeError) throw e;
|
if (e instanceof FileTooLargeError) throw e;
|
||||||
console.log(e);
|
console.log(e);
|
||||||
const zip = new AdmZip(this.request.files.file.filepath);
|
let zip: AdmZip;
|
||||||
|
try {
|
||||||
|
zip = new AdmZip(this.request.files.file.filepath);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ValidationError('zip', null, e.message);
|
||||||
|
}
|
||||||
for (const entry of zip.getEntries()) {
|
for (const entry of zip.getEntries()) {
|
||||||
try {
|
try {
|
||||||
const buf = entry.getData();
|
const buf = entry.getData();
|
||||||
|
|||||||
@@ -37,7 +37,12 @@ class ProblemImportHydroHandler extends Handler {
|
|||||||
if (keepUser) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
if (keepUser) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
||||||
if (!this.request.files.file) throw new ValidationError('file');
|
if (!this.request.files.file) throw new ValidationError('file');
|
||||||
const tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
|
const tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
|
||||||
const zip = new AdmZip(this.request.files.file.filepath);
|
let zip: AdmZip;
|
||||||
|
try {
|
||||||
|
zip = new AdmZip(this.request.files.file.filepath);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ValidationError('zip', null, e.message);
|
||||||
|
}
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
zip.extractAllToAsync(tmpdir, true, (err) => {
|
zip.extractAllToAsync(tmpdir, true, (err) => {
|
||||||
if (err) reject(err);
|
if (err) reject(err);
|
||||||
|
|||||||
@@ -727,7 +727,12 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
|||||||
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||||
const files = [];
|
const files = [];
|
||||||
if (filename.endsWith('.zip') && type === 'testdata') {
|
if (filename.endsWith('.zip') && type === 'testdata') {
|
||||||
const zip = new AdmZip(this.request.files.file.filepath);
|
let zip: AdmZip;
|
||||||
|
try {
|
||||||
|
zip = new AdmZip(this.request.files.file.filepath);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ValidationError('zip', null, e.message);
|
||||||
|
}
|
||||||
const entries = zip.getEntries();
|
const entries = zip.getEntries();
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (!entry.name) continue;
|
if (!entry.name) continue;
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ fs.ensureDirSync('/tmp/hydro/import-qduoj');
|
|||||||
|
|
||||||
class ImportQduojHandler extends Handler {
|
class ImportQduojHandler extends Handler {
|
||||||
async fromFile(domainId: string, zipfile: string) {
|
async fromFile(domainId: string, zipfile: string) {
|
||||||
const zip = new AdmZip(zipfile);
|
let zip: AdmZip;
|
||||||
|
try {
|
||||||
|
zip = new AdmZip(zipfile);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ValidationError('zip', null, e.message);
|
||||||
|
}
|
||||||
const tmp = path.resolve(os.tmpdir(), 'hydro', 'import-qduoj', String.random(32));
|
const tmp = path.resolve(os.tmpdir(), 'hydro', 'import-qduoj', String.random(32));
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
zip.extractAllToAsync(tmp, true, (err) => (err ? reject(err) : resolve(null)));
|
zip.extractAllToAsync(tmp, true, (err) => (err ? reject(err) : resolve(null)));
|
||||||
|
|||||||
Reference in new issue
Block a user