core: import: handle error message for invalid zip

This commit is contained in:
undefined committed 2022-09-27 02:43:19 +08:00
1 parent cb424c9cac
commit 895d50530a
4 files changed
+24 -4

No files matched your search

+6 -1
View File
@@ -15,7 +15,12 @@ fs.ensureDirSync('/tmp/hydro/import-qduoj');
class ImportQduojHandler extends Handler {
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));
await new Promise((resolve, reject) => {
zip.extractAllToAsync(tmp, true, (err) => (err ? reject(err) : resolve(null)));