mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix icpc problem package import (#966)
This commit is contained in:
1 parent
f305110381
commit
56311e1209
1 file changed
+24
-2
@@ -8,7 +8,7 @@ import yaml from 'js-yaml';
|
|||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
import { Filter, ObjectId } from 'mongodb';
|
import { Filter, ObjectId } from 'mongodb';
|
||||||
import type { Readable } from 'stream';
|
import type { Readable } from 'stream';
|
||||||
import { ProblemConfigFile } from '@hydrooj/common';
|
import { ProblemConfigFile, ProblemType } from '@hydrooj/common';
|
||||||
import { Logger, size, streamToBuffer } from '@hydrooj/utils/lib/utils';
|
import { Logger, size, streamToBuffer } from '@hydrooj/utils/lib/utils';
|
||||||
import { Context } from '../context';
|
import { Context } from '../context';
|
||||||
import { FileUploadError, ProblemNotFoundError, ValidationError } from '../error';
|
import { FileUploadError, ProblemNotFoundError, ValidationError } from '../error';
|
||||||
@@ -41,6 +41,7 @@ function sortable(source: string, namespaces: Record<string, string>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findOverrideContent(dir: string, base: string) {
|
function findOverrideContent(dir: string, base: string) {
|
||||||
|
if (!fs.existsSync(dir)) return null;
|
||||||
let files = fs.readdirSync(dir);
|
let files = fs.readdirSync(dir);
|
||||||
if (files.includes(`${base}.md`)) return fs.readFileSync(path.join(dir, `${base}.md`), 'utf8');
|
if (files.includes(`${base}.md`)) return fs.readFileSync(path.join(dir, `${base}.md`), 'utf8');
|
||||||
if (files.includes(`${base}.pdf`)) return `@[PDF](file://${base}.pdf)`;
|
if (files.includes(`${base}.pdf`)) return `@[PDF](file://${base}.pdf)`;
|
||||||
@@ -478,7 +479,11 @@ export class ProblemModel {
|
|||||||
throw new ValidationError('file', null, 'Invalid file');
|
throw new ValidationError('file', null, 'Invalid file');
|
||||||
}
|
}
|
||||||
const files = await fs.readdir(tmpdir, { withFileTypes: true });
|
const files = await fs.readdir(tmpdir, { withFileTypes: true });
|
||||||
problems = files.filter((f) => f.isDirectory()).map((i) => i.name);
|
if (files.find((f) => f.name === 'problem.yaml')) {
|
||||||
|
problems = ['.']; // special case for ICPC problem package
|
||||||
|
} else {
|
||||||
|
problems = files.filter((f) => f.isDirectory()).map((i) => i.name);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (options.delSource) await fs.remove(tmpdir);
|
if (options.delSource) await fs.remove(tmpdir);
|
||||||
}
|
}
|
||||||
@@ -549,6 +554,7 @@ export class ProblemModel {
|
|||||||
if ((pdoc as any).limits) {
|
if ((pdoc as any).limits) {
|
||||||
config.time = (pdoc as any).limits.time_limit;
|
config.time = (pdoc as any).limits.time_limit;
|
||||||
config.memory = (pdoc as any).limits.memory;
|
config.memory = (pdoc as any).limits.memory;
|
||||||
|
configChanged = true;
|
||||||
}
|
}
|
||||||
const docId = overridePid
|
const docId = overridePid
|
||||||
? (await ProblemModel.edit(domainId, overridePid, {
|
? (await ProblemModel.edit(domainId, overridePid, {
|
||||||
@@ -577,6 +583,22 @@ export class ProblemModel {
|
|||||||
: null)?.(domainId, docId, file, path.join(loc, file));
|
: null)?.(domainId, docId, file, path.join(loc, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (const [f, loc] of await getFiles('output_validators')) {
|
||||||
|
if (f.isFile()) continue;
|
||||||
|
const sub = await fs.readdir(loc);
|
||||||
|
for (const file of sub) {
|
||||||
|
if (file === 'testlib.h') continue;
|
||||||
|
await ProblemModel.addTestdata(domainId, docId, file, path.join(loc, file));
|
||||||
|
if (file === 'checker') {
|
||||||
|
config.checker_type = 'testlib';
|
||||||
|
config.checker = file;
|
||||||
|
} else if (file === 'interactor') {
|
||||||
|
config.type = ProblemType.Interactive;
|
||||||
|
config.interactor = file;
|
||||||
|
}
|
||||||
|
configChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (const [f, loc] of await getFiles('additional_file', 'attachments', 'statement', 'problem_statement')) {
|
for (const [f, loc] of await getFiles('additional_file', 'attachments', 'statement', 'problem_statement')) {
|
||||||
if (!f.isFile()) continue;
|
if (!f.isFile()) continue;
|
||||||
await ProblemModel.addAdditionalFile(domainId, docId, f.name, loc);
|
await ProblemModel.addAdditionalFile(domainId, docId, f.name, loc);
|
||||||
|
|||||||
Reference in new issue
Block a user