mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: langs: add validAs option
This commit is contained in:
4 files changed
+19
-28
No files matched your search
@@ -340,7 +340,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
|
||||
let baseLangs;
|
||||
if (this.pdoc.config.type === 'remote_judge') {
|
||||
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;
|
||||
} else {
|
||||
baseLangs = Object.keys(setting.langs).filter((i) => !setting.langs[i].remote);
|
||||
@@ -512,7 +512,6 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
|
||||
}
|
||||
if (pretest) {
|
||||
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)) {
|
||||
throw new ProblemNotAllowPretestError('type');
|
||||
}
|
||||
|
||||
@@ -68,41 +68,27 @@ export default class RecordModel {
|
||||
if (!rids.length) return null;
|
||||
const rdoc = await RecordModel.get(domainId, rids[0]);
|
||||
if (!rdoc) return null;
|
||||
let data: FileInfo[] = [];
|
||||
let source = `${domainId}/${rdoc.pid}`;
|
||||
meta = { ...meta, problemOwner: 1 };
|
||||
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.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}`;
|
||||
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) => ({
|
||||
...(pdoc.config as any),
|
||||
priority,
|
||||
type: 'judge',
|
||||
type,
|
||||
rid,
|
||||
domainId,
|
||||
config,
|
||||
data,
|
||||
data: pdoc.data,
|
||||
source,
|
||||
meta,
|
||||
} as any)));
|
||||
|
||||
@@ -15,7 +15,10 @@ export interface LangConfig {
|
||||
key: string;
|
||||
hidden: boolean;
|
||||
analysis?: string;
|
||||
/** @deprecated */
|
||||
remote?: string;
|
||||
validAs?: Record<string, string>;
|
||||
/** @deprecated */
|
||||
pretest?: string | false;
|
||||
comment?: string | [string, string];
|
||||
compile_time_limit?: number;
|
||||
@@ -47,6 +50,7 @@ export function parseLang(config: string): Record<string, LangConfig> {
|
||||
entry.key = key;
|
||||
entry.hidden ||= false;
|
||||
entry.disabled ||= false;
|
||||
entry.validAs ||= {};
|
||||
}
|
||||
return file;
|
||||
}
|
||||
@@ -42,7 +42,9 @@ class AccountService {
|
||||
const end = (payload) => JudgeHandler.end({ ...payload, rid: task.rid });
|
||||
await next({ status: STATUS.STATUS_FETCHED });
|
||||
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) {
|
||||
const msg = `Hydro submission #${task.rid}@${new Date().getTime()}`;
|
||||
if (typeof comment === 'string') task.code = `${comment} ${msg}\n${task.code}`;
|
||||
|
||||
Reference in new issue
Block a user