mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
import-qduoj: fix
This commit is contained in:
1 parent
991ffa6c86
commit
84d7e1b95d
6 files changed
+18
-13
No files matched your search
@@ -6,7 +6,7 @@ import AdmZip from 'adm-zip';
|
||||
import yaml from 'js-yaml';
|
||||
import { ContentNode, LocalProblemConfig } from 'hydrooj';
|
||||
import { Route, Handler } from 'hydrooj/dist/service/server';
|
||||
import * as storage from 'hydrooj/dist/service/storage';
|
||||
import storage from 'hydrooj/dist/service/storage';
|
||||
import { BadRequestError, ValidationError } from 'hydrooj/dist/error';
|
||||
import { ProblemAdd } from 'hydrooj/dist/lib/ui';
|
||||
import * as problem from 'hydrooj/dist/model/problem';
|
||||
@@ -19,7 +19,7 @@ class ImportQduojHandler extends Handler {
|
||||
const zip = new AdmZip(zipfile);
|
||||
const tmp = path.resolve(os.tmpdir(), 'hydro', 'import-qduoj', String.random(32));
|
||||
await new Promise((resolve, reject) => {
|
||||
zip.extractAllToAsync(tmp, true, (err) => (err ? resolve(null) : reject(err)));
|
||||
zip.extractAllToAsync(tmp, true, (err) => (err ? reject(err) : resolve(null)));
|
||||
});
|
||||
try {
|
||||
const folders = await fs.readdir(tmp);
|
||||
@@ -73,6 +73,8 @@ class ImportQduojHandler extends Handler {
|
||||
text: pdoc.source.value,
|
||||
});
|
||||
}
|
||||
const n = await problem.get(domainId, pdoc.display_id);
|
||||
if (n) pdoc.display_id = null;
|
||||
const pid = await problem.add(domainId, pdoc.display_id, pdoc.title, content, this.user._id, pdoc.tags);
|
||||
const config: LocalProblemConfig = {
|
||||
time: `${pdoc.time_limit}ms`,
|
||||
@@ -82,11 +84,11 @@ class ImportQduojHandler extends Handler {
|
||||
for (const tc of pdoc.test_case_score) {
|
||||
await storage.put(
|
||||
`problem/${domainId}/${pid}/testdata/${tc.input_name}`,
|
||||
path.join(tmp, 'testcase', tc.input_name),
|
||||
path.join(tmp, folder, 'testcase', tc.input_name),
|
||||
);
|
||||
await storage.put(
|
||||
`problem/${domainId}/${pid}/testdata/${tc.output_name}`,
|
||||
path.join(tmp, 'testcase', tc.output_name),
|
||||
path.join(tmp, folder, 'testcase', tc.output_name),
|
||||
);
|
||||
config.subtasks.push({
|
||||
score: tc.score,
|
||||
@@ -103,6 +105,8 @@ class ImportQduojHandler extends Handler {
|
||||
const data = await storage.list(`problem/${domainId}/${pid}/testdata/`, true);
|
||||
await problem.edit(domainId, pid, { html: true, data });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
await fs.remove(tmp);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user