core&judge: add isTrusted option

This commit is contained in:
undefined committed 2024-11-03 18:27:41 +08:00
1 parent b6834c5c55
commit 4d7fa024e7
4 files changed
+12 -4

No files matched your search

+2 -1
View File
@@ -41,6 +41,7 @@ interface Args {
next: NextFunction;
key: string;
isSelfSubmission: boolean;
trusted: boolean;
lang: string;
langConfig?: LangConfig;
}
@@ -85,6 +86,6 @@ export default async function readCases(folder: string, cfg: ProblemConfigFile =
}
result.subtasks = normalizeSubtasks(result.subtasks || [], checkFile, config.time, config.memory, false, timeRate, memoryRate);
if (result.key && args.key !== result.key) throw new FormatError('Incorrect secret key');
if (!result.key) isValidConfig(result);
if (!result.key && !args.trusted) isValidConfig(result);
return result;
}
+1
View File
@@ -112,6 +112,7 @@ export class JudgeTask {
next: this.next,
isSelfSubmission: this.meta.problemOwner === this.request.uid,
key: md5(`${this.source}/${getConfig('secret')}`),
trusted: this.request.trusted,
lang: this.lang,
langConfig: (this.request.type === 'generate' || ['objective', 'submit_answer'].includes(this.request.config.type))
? null : this.session.getLang(this.lang),
+1
View File
@@ -348,6 +348,7 @@ export interface JudgeRequest extends Omit<RecordDoc, '_id' | 'testCases'> {
meta: JudgeMeta;
data: FileInfo[];
source: string;
trusted: boolean;
}
export interface ScoreboardNode {
+8 -3
View File
@@ -14,6 +14,7 @@ import db from '../service/db';
import { MaybeArray, NumberKeys } from '../typeutils';
import { ArgMethod, buildProjection, Time } from '../utils';
import { STATUS } from './builtin';
import DomainModel from './domain';
import problem from './problem';
import task from './task';
@@ -80,11 +81,13 @@ export default class RecordModel {
static async judge(domainId: string, rids: MaybeArray<ObjectId>, priority = 0, config: ProblemConfigFile = {}, meta: Partial<JudgeMeta> = {}) {
rids = rids instanceof Array ? rids : [rids];
if (!rids.length) return null;
const rdocs = (await Promise.all(rids.map((rid) => RecordModel.get(domainId, rid)))).filter((i) => i);
const rdocs = await RecordModel.getMulti(domainId, { _id: { $in: rids } }).toArray();
if (!rdocs.length) return null;
let source = `${domainId}/${rdocs[0].pid}`;
await task.deleteMany({ rid: { $in: rids } });
let pdoc = await problem.get(domainId, rdocs[0].pid);
let [pdoc] = await Promise.all([
problem.get(domainId, rdocs[0].pid),
task.deleteMany({ rid: { $in: rids } }),
]);
if (!pdoc) throw new ProblemNotFoundError(domainId, rdocs[0].pid);
if (pdoc.reference) {
pdoc = await problem.get(pdoc.reference.domainId, pdoc.reference.pid);
@@ -92,6 +95,7 @@ export default class RecordModel {
source = `${pdoc.domainId}/${pdoc.docId}`;
}
meta = { ...meta, problemOwner: pdoc.owner };
const ddoc = await DomainModel.get(pdoc.domainId);
return await task.addMany(rdocs.map((rdoc) => {
let type = 'judge';
if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
@@ -110,6 +114,7 @@ export default class RecordModel {
},
data: pdoc.data,
source,
trusted: ddoc.isTrusted,
meta,
} as any);
}));