core&judge: add isTrusted option

This commit is contained in:
undefined committed 2024-11-13 11:31:34 +08:00
1 parent d33c186571
commit f5af57fcfa
4 files changed
+12 -4

No files matched your search

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