judge: better config validate

pull/39/head
undefined 4 years ago
parent 68286607e9
commit 5dd5dca675

@ -7,7 +7,7 @@
"author": "undefined <masnn0@outlook.com>",
"license": "AGPL-3.0-only",
"dependencies": {
"nodejieba": "^2.4.2"
"nodejieba": "^2.5.1"
},
"devDependencies": {},
"peerDependencies": {

@ -1,7 +1,7 @@
import fs from 'fs-extra';
import path from 'path';
import yaml from 'js-yaml';
import { Dictionary } from 'lodash';
import { Dictionary, sum } from 'lodash';
import { argv } from 'yargs';
import { FormatError, SystemError } from './error';
import { parseTimeMS, parseMemoryMB, ensureFile } from './utils';
@ -285,11 +285,10 @@ function convertIniConfig(ini: string) {
}
function isValidConfig(config) {
if (config.count > (argv.max_testcases_count as string || 100)) throw new FormatError('Too many testcases. Cancelled.');
let total_time = 0;
for (const subtask of config.subtasks) {
total_time += subtask.time_limit_ms * subtask.cases.length;
if (config.count > (argv.max_testcases_count as string || 100)) {
throw new FormatError('Too many testcases. Cancelled.');
}
const total_time = sum(config.subtasks.map((subtask) => subtask.time_limit_ms * subtask.cases.length));
if (total_time > (+argv.max_time_limit || 60) * 1000) {
throw new FormatError('Total time limit longer than {0}s. Cancelled.', [+argv.max_time_limit || 60]);
}

@ -1,5 +1,4 @@
import { ObjectID, FilterQuery } from 'mongodb';
import { filter, sortBy } from 'lodash';
import * as user from './user';
import * as problem from './problem';
import * as document from './document';

Loading…
Cancel
Save