mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: import: support using extracted folder
This commit is contained in:
1 file changed
+19
-12
@@ -407,19 +407,26 @@ export class ProblemModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async import(domainId: string, filepath: string, operator: number) {
|
static async import(domainId: string, filepath: string, operator: number) {
|
||||||
const tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
|
let tmpdir = '';
|
||||||
let zip: AdmZip;
|
if (filepath.endsWith('.zip')) {
|
||||||
try {
|
tmpdir = path.join(os.tmpdir(), 'hydro', `${Math.random()}.import`);
|
||||||
zip = new AdmZip(filepath);
|
let zip: AdmZip;
|
||||||
} catch (e) {
|
try {
|
||||||
throw new ValidationError('zip', null, e.message);
|
zip = new AdmZip(filepath);
|
||||||
}
|
} catch (e) {
|
||||||
await new Promise((resolve, reject) => {
|
throw new ValidationError('zip', null, e.message);
|
||||||
zip.extractAllToAsync(tmpdir, true, (err) => {
|
}
|
||||||
if (err) reject(err);
|
await new Promise((resolve, reject) => {
|
||||||
resolve(null);
|
zip.extractAllToAsync(tmpdir, true, (err) => {
|
||||||
|
if (err) reject(err);
|
||||||
|
resolve(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} else if (fs.statSync(filepath).isDirectory()) {
|
||||||
|
tmpdir = filepath;
|
||||||
|
} else {
|
||||||
|
throw new ValidationError('file', null, 'Invalid file');
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const problems = await fs.readdir(tmpdir, { withFileTypes: true });
|
const problems = await fs.readdir(tmpdir, { withFileTypes: true });
|
||||||
for (const p of problems) {
|
for (const p of problems) {
|
||||||
|
|||||||
Reference in new issue
Block a user