mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: import: show progress
This commit is contained in:
4 files changed
+23
-9
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import { sleep } from '@hydrooj/utils';
|
||||
import { Context } from '../context';
|
||||
import { ValidationError } from '../error';
|
||||
import { PERM, PRIV } from '../model/builtin';
|
||||
import MessageModel from '../model/message';
|
||||
import problem from '../model/problem';
|
||||
import { Handler, param, Types } from '../service/server';
|
||||
|
||||
@@ -15,8 +17,16 @@ class ProblemImportHydroHandler extends Handler {
|
||||
if (keepUser) this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
||||
if (!this.request.files.file) throw new ValidationError('file');
|
||||
if (preferredPrefix && !/^[a-zA-Z]+$/.test(preferredPrefix)) throw new ValidationError('preferredPrefix');
|
||||
await problem.import(domainId, this.request.files.file.filepath, keepUser ? null : this.user._id, preferredPrefix);
|
||||
this.response.redirect = this.url('problem_main');
|
||||
const promise = problem.import(
|
||||
domainId, this.request.files.file.filepath, keepUser ? null : this.user._id,
|
||||
preferredPrefix, this.progress.bind(this),
|
||||
).catch((e) => MessageModel.send(1, this.user._id, `Import failed: ${e.message}\n${e.stack}`));
|
||||
let resolved = false;
|
||||
await Promise.race([
|
||||
promise.then(() => { resolved = true; }),
|
||||
sleep(5000),
|
||||
]);
|
||||
this.response.redirect = this.url('problem_main', resolved ? {} : { query: { showImport: 1 } });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user