import-qduoj: use os.tmpdir

This commit is contained in:
undefined committed 2022-12-29 18:07:45 +08:00
1 parent 627c46113f
commit 4d4098ee84
1 file changed
+3 -2
+3 -2
View File
@@ -6,7 +6,8 @@ import {
ProblemConfigFile, ProblemModel, ValidationError, yaml, ProblemConfigFile, ProblemModel, ValidationError, yaml,
} from 'hydrooj'; } from 'hydrooj';
fs.ensureDirSync('/tmp/hydro/import-qduoj'); const tmpdir = path.join(os.tmpdir(), 'hydro', 'import-qduoj');
fs.ensureDirSync(tmpdir);
class ImportQduojHandler extends Handler { class ImportQduojHandler extends Handler {
async fromFile(domainId: string, zipfile: string) { async fromFile(domainId: string, zipfile: string) {
@@ -16,7 +17,7 @@ class ImportQduojHandler extends Handler {
} catch (e) { } catch (e) {
throw new ValidationError('zip', null, e.message); throw new ValidationError('zip', null, e.message);
} }
const tmp = path.resolve(os.tmpdir(), 'hydro', 'import-qduoj', String.random(32)); const tmp = path.resolve(tmpdir, 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)));
}); });