core: langs: add validAs option

This commit is contained in:
undefined committed 2023-05-10 20:20:12 +08:00
1 parent d20c405da9
commit 1b1faa9ff9
4 files changed
+19 -28

No files matched your search

+1 -2
View File
@@ -340,7 +340,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
let baseLangs; let baseLangs;
if (this.pdoc.config.type === 'remote_judge') { if (this.pdoc.config.type === 'remote_judge') {
const p = this.pdoc.config.subType; const p = this.pdoc.config.subType;
const dl = [p, ...Object.keys(setting.langs).filter((i) => i.startsWith(`${p}.`))]; const dl = [p, ...Object.keys(setting.langs).filter((i) => i.startsWith(`${p}.`) || setting.langs[i].validAs[p])];
baseLangs = dl; baseLangs = dl;
} else { } else {
baseLangs = Object.keys(setting.langs).filter((i) => !setting.langs[i].remote); baseLangs = Object.keys(setting.langs).filter((i) => !setting.langs[i].remote);
@@ -512,7 +512,6 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
} }
if (pretest) { if (pretest) {
if (setting.langs[lang]?.pretest) lang = setting.langs[lang].pretest as string; if (setting.langs[lang]?.pretest) lang = setting.langs[lang].pretest as string;
if (setting.langs[lang]?.pretest === false) throw new ProblemNotAllowPretestError('language');
if (!['default', 'fileio', 'remote_judge'].includes(this.response.body.pdoc.config?.type)) { if (!['default', 'fileio', 'remote_judge'].includes(this.response.body.pdoc.config?.type)) {
throw new ProblemNotAllowPretestError('type'); throw new ProblemNotAllowPretestError('type');
} }
+11 -25
View File
@@ -68,41 +68,27 @@ export default class RecordModel {
if (!rids.length) return null; if (!rids.length) return null;
const rdoc = await RecordModel.get(domainId, rids[0]); const rdoc = await RecordModel.get(domainId, rids[0]);
if (!rdoc) return null; if (!rdoc) return null;
let data: FileInfo[] = [];
let source = `${domainId}/${rdoc.pid}`; let source = `${domainId}/${rdoc.pid}`;
meta = { ...meta, problemOwner: 1 };
await task.deleteMany({ rid: { $in: rids } }); await task.deleteMany({ rid: { $in: rids } });
if (rdoc.pid) { let pdoc = await problem.get(rdoc.domainId, rdoc.pid);
let pdoc = await problem.get(rdoc.domainId, rdoc.pid); if (!pdoc) throw new ProblemNotFoundError(rdoc.domainId, rdoc.pid);
if (pdoc.reference) {
pdoc = await problem.get(pdoc.reference.domainId, pdoc.reference.pid);
if (!pdoc) throw new ProblemNotFoundError(rdoc.domainId, rdoc.pid); if (!pdoc) throw new ProblemNotFoundError(rdoc.domainId, rdoc.pid);
if (pdoc.reference) {
pdoc = await problem.get(pdoc.reference.domainId, pdoc.reference.pid);
if (!pdoc) throw new ProblemNotFoundError(rdoc.domainId, rdoc.pid);
}
meta.problemOwner = pdoc.owner;
source = `${pdoc.domainId}/${pdoc.docId}`; source = `${pdoc.domainId}/${pdoc.docId}`;
data = pdoc.data;
if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
config.type = pdoc.config.type === 'fileio' ? 'default' : pdoc.config.type as any;
if (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) {
return await task.addMany(rids.map((rid) => ({
...(pdoc.config as any),
priority,
type: 'remotejudge',
rid,
domainId,
config,
data,
} as any)));
}
} }
meta = { ...meta, problemOwner: pdoc.owner };
if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
const type = (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) ? 'remotejudge' : 'judge';
config.type = pdoc.config.type === 'fileio' ? 'default' : pdoc.config.type as any;
return await task.addMany(rids.map((rid) => ({ return await task.addMany(rids.map((rid) => ({
...(pdoc.config as any),
priority, priority,
type: 'judge', type,
rid, rid,
domainId, domainId,
config, config,
data, data: pdoc.data,
source, source,
meta, meta,
} as any))); } as any)));
+4
View File
@@ -15,7 +15,10 @@ export interface LangConfig {
key: string; key: string;
hidden: boolean; hidden: boolean;
analysis?: string; analysis?: string;
/** @deprecated */
remote?: string; remote?: string;
validAs?: Record<string, string>;
/** @deprecated */
pretest?: string | false; pretest?: string | false;
comment?: string | [string, string]; comment?: string | [string, string];
compile_time_limit?: number; compile_time_limit?: number;
@@ -47,6 +50,7 @@ export function parseLang(config: string): Record<string, LangConfig> {
entry.key = key; entry.key = key;
entry.hidden ||= false; entry.hidden ||= false;
entry.disabled ||= false; entry.disabled ||= false;
entry.validAs ||= {};
} }
return file; return file;
} }
+3 -1
View File
@@ -42,7 +42,9 @@ class AccountService {
const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid }); const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid });
await next({ status: STATUS.STATUS_FETCHED }); await next({ status: STATUS.STATUS_FETCHED });
try { try {
const comment = SettingModel.langs[task.lang].comment; const langConfig = SettingModel.langs[task.lang];
if (langConfig.validAs?.[this.account.type]) task.lang = langConfig.validAs[this.account.type];
const comment = langConfig.comment;
if (comment) { if (comment) {
const msg = `Hydro submission #${task.rid}@${new Date().getTime()}`; const msg = `Hydro submission #${task.rid}@${new Date().getTime()}`;
if (typeof comment === 'string') task.code = `${comment} ${msg}\n${task.code}`; if (typeof comment === 'string') task.code = `${comment} ${msg}\n${task.code}`;