mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
update interface: ProblemConfig
This commit is contained in:
1 parent
92335d8529
commit
57881792f3
15 files changed
+226
-145
No files matched your search
@@ -304,14 +304,10 @@ class ContestProblemSubmitHandler extends ContestProblemHandler {
|
||||
@param('code', Types.String)
|
||||
async post(domainId: string, tid: ObjectID, lang: string, code: string) {
|
||||
await this.limitRate('add_record', 60, 100);
|
||||
const rid = await record.add(domainId, {
|
||||
pid: this.pdoc.docId,
|
||||
uid: this.user._id,
|
||||
tid: this.tdoc.docId,
|
||||
ttype: document.TYPE_CONTEST,
|
||||
lang,
|
||||
code,
|
||||
}, true);
|
||||
const rid = await record.add(domainId, this.pdoc.docId, this.user._id, lang, code, true, {
|
||||
type: document.TYPE_CONTEST,
|
||||
tid,
|
||||
});
|
||||
const [rdoc] = await Promise.all([
|
||||
record.get(domainId, rid),
|
||||
contest.updateStatus(domainId, this.tdoc.docId, this.user._id, rid, this.pdoc.docId),
|
||||
|
||||
@@ -181,9 +181,10 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
|
||||
if (!tsdoc.attend) throw new HomeworkNotAttendedError(tid);
|
||||
if (!contest.isOngoing(this.tdoc)) throw new HomeworkNotLiveError(tid);
|
||||
if (!this.tdoc.pids.includes(pid)) throw new ProblemNotFoundError(domainId, pid);
|
||||
const rid = await record.add(domainId, {
|
||||
pid, lang, code, uid: this.user._id, tid, hidden: true, ttype: document.TYPE_HOMEWORK,
|
||||
}, true);
|
||||
const rid = await record.add(domainId, pid, this.user._id, lang, code, true, {
|
||||
type: document.TYPE_HOMEWORK,
|
||||
tid,
|
||||
});
|
||||
const [rdoc] = await Promise.all([
|
||||
record.get(domainId, rid),
|
||||
contest.updateStatus(domainId, tid, this.user._id,
|
||||
|
||||
+3
-40
@@ -16,11 +16,11 @@ import {
|
||||
async function _postJudge(rdoc: Rdoc) {
|
||||
const accept = rdoc.status === builtin.STATUS.STATUS_ACCEPTED;
|
||||
const tasks = [];
|
||||
if (rdoc.tid) {
|
||||
if (rdoc.contest) {
|
||||
tasks.push(
|
||||
contest.updateStatus(
|
||||
rdoc.domainId, rdoc.tid, rdoc.uid,
|
||||
rdoc._id, rdoc.pid, accept, rdoc.score, rdoc.ttype,
|
||||
rdoc.domainId, rdoc.contest.tid, rdoc.uid,
|
||||
rdoc._id, rdoc.pid, accept, rdoc.score, rdoc.contest.type,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -93,42 +93,6 @@ export async function end(body: JudgeResultBody) {
|
||||
bus.publish('record_change', { rdoc }); // trigger a full update
|
||||
}
|
||||
|
||||
class PretestHandler extends Handler {
|
||||
@param('pid', Types.UnsignedInt, true)
|
||||
@param('code', Types.String)
|
||||
@param('lang', Types.String)
|
||||
@param('time', Types.String, true)
|
||||
@param('memory', Types.String, true)
|
||||
@param('input', Types.String, true)
|
||||
async post(
|
||||
domainId: string, pid = 0,
|
||||
code: string, lang: string,
|
||||
time = '1s', memory = '256m', input = '',
|
||||
) {
|
||||
if (pid) {
|
||||
const pdoc = await problem.get(domainId, pid);
|
||||
if (pdoc.config) {
|
||||
const config: any = yaml.safeLoad(pdoc.config);
|
||||
if (config.time) time = config.time;
|
||||
if (config.memory) memory = config.memory;
|
||||
}
|
||||
}
|
||||
const rid = await record.add(domainId, {
|
||||
pid,
|
||||
uid: this.user._id,
|
||||
type: 'run',
|
||||
time: parseTimeMS(time),
|
||||
memory: parseMemoryMB(memory),
|
||||
input,
|
||||
lang,
|
||||
code,
|
||||
hidden: true,
|
||||
}, true);
|
||||
this.response.body = { rid };
|
||||
this.response.redirect = this.url('record_detail', { rid });
|
||||
}
|
||||
}
|
||||
|
||||
class JudgeHandler extends Handler {
|
||||
async get({ check = false }) {
|
||||
if (check) return;
|
||||
@@ -174,7 +138,6 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
||||
}
|
||||
|
||||
export async function apply() {
|
||||
Route('pretest', '/pretest', PretestHandler);
|
||||
Route('judge', '/judge', JudgeHandler, builtin.PRIV.PRIV_JUDGE);
|
||||
Connection('judge_conn', '/judge/conn', JudgeConnectionHandler, builtin.PRIV.PRIV_JUDGE);
|
||||
}
|
||||
|
||||
+3
-10
@@ -89,18 +89,11 @@ class SystemScriptHandler extends SystemHandler {
|
||||
|
||||
@param('id', Types.String)
|
||||
@param('args', Types.String, true)
|
||||
async post(domainId: string, id: string, args = '{}') {
|
||||
async post(domainId: string, id: string, raw = '{}') {
|
||||
if (!global.Hydro.script[id]) throw new ValidationError('id');
|
||||
args = JSON.parse(args);
|
||||
const args = JSON.parse(raw);
|
||||
validate(global.Hydro.script[id].validate, args);
|
||||
const rid = await record.add(domainId, {
|
||||
pid: -1,
|
||||
uid: this.user._id,
|
||||
lang: '-',
|
||||
code: id,
|
||||
status: STATUS.STATUS_JUDGING,
|
||||
hidden: true,
|
||||
}, false);
|
||||
const rid = await record.add(domainId, -1, this.user._id, '-', id, false, { input: 'raw' });
|
||||
judge.next({ domainId, rid, message: `Running script: ${id}` });
|
||||
async function report(data) {
|
||||
judge.next({ domainId, rid, ...data });
|
||||
|
||||
+22
-15
@@ -24,7 +24,9 @@ import {
|
||||
ValidationError,
|
||||
PermissionError,
|
||||
} from '../error';
|
||||
import { Pdoc, User, Rdoc } from '../interface';
|
||||
import {
|
||||
Pdoc, User, Rdoc, ProblemConfig,
|
||||
} from '../interface';
|
||||
|
||||
const parseCategory = (value: string) => {
|
||||
if (!value) return [];
|
||||
@@ -179,12 +181,9 @@ class ProblemDetailHandler extends ProblemHandler {
|
||||
if (this.pdoc.hidden && this.pdoc.owner !== this.user._id) {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
}
|
||||
const config: any = this.pdoc.config ? yaml.safeLoad(this.pdoc.config) : {};
|
||||
this.udoc = await user.getById(domainId, this.pdoc.owner);
|
||||
this.response.body = {
|
||||
pdoc: this.pdoc,
|
||||
time: config.time,
|
||||
memory: config.memory,
|
||||
udoc: this.udoc,
|
||||
title: this.pdoc.title,
|
||||
path: [
|
||||
@@ -255,14 +254,12 @@ class ProblemSubmitHandler extends ProblemDetailHandler {
|
||||
@param('lang', Types.String)
|
||||
@param('code', Types.String)
|
||||
async post(domainId: string, lang: string, code: string) {
|
||||
const rid = await record.add(domainId, {
|
||||
uid: this.user._id, lang, code, pid: this.pdoc.docId,
|
||||
}, true);
|
||||
const rid = await record.add(domainId, this.pdoc.docId, this.user._id, lang, code, true);
|
||||
const [rdoc] = await Promise.all([
|
||||
record.get(domainId, rid),
|
||||
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
||||
]);
|
||||
bus.publish('record_change', rdoc);
|
||||
bus.publish('record_change', { rdoc });
|
||||
this.response.body = { rid };
|
||||
this.response.redirect = this.url('record_detail', { rid });
|
||||
}
|
||||
@@ -274,11 +271,18 @@ class ProblemPretestHandler extends ProblemDetailHandler {
|
||||
@param('input', Types.String, true)
|
||||
async post(domainId: string, lang: string, code: string, input: string = '') {
|
||||
this.limitRate('add_record', 3600, 100);
|
||||
const rid = await record.add(domainId, {
|
||||
uid: this.user._id, lang, code, pid: this.pdoc.docId, input,
|
||||
}, true);
|
||||
// TODO parseConfig
|
||||
const rid = await record.add(
|
||||
domainId, this.pdoc.docId, this.user._id,
|
||||
lang, code, true,
|
||||
{
|
||||
input,
|
||||
time: 1000,
|
||||
memory: 256,
|
||||
},
|
||||
);
|
||||
const rdoc = await record.get(domainId, rid);
|
||||
bus.publish('record_change', rdoc);
|
||||
bus.publish('record_change', { rdoc });
|
||||
this.response.body = { rid };
|
||||
}
|
||||
}
|
||||
@@ -311,7 +315,8 @@ class ProblemPretestConnectionHandler extends ConnectionHandler {
|
||||
rdoc.testCases = rdoc.testCases.map((c) => ({
|
||||
status: c.status,
|
||||
}));
|
||||
if (rdoc.tid) return;
|
||||
// TODO handle update
|
||||
if (rdoc.contest) return;
|
||||
this.send({ rdoc });
|
||||
}
|
||||
|
||||
@@ -354,9 +359,11 @@ class ProblemSettingsHandler extends ProblemManageHandler {
|
||||
|
||||
@param('pid', Types.String, null, parsePid)
|
||||
@param('yaml', Types.String)
|
||||
async postConfig(domainId: string, pid: string | number, yaml: string) {
|
||||
async postConfig(domainId: string, pid: string | number, cfg: string) {
|
||||
const pdoc = await problem.get(domainId, pid);
|
||||
await problem.edit(domainId, pdoc.docId, { config: yaml });
|
||||
// TODO validate
|
||||
const config = yaml.safeLoad(cfg);
|
||||
await problem.edit(domainId, pdoc.docId, { config });
|
||||
this.back();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,14 +63,13 @@ class RecordDetailHandler extends RecordHandler {
|
||||
async get(domainId: string, rid: ObjectID) {
|
||||
this.response.template = 'record_detail.html';
|
||||
const rdoc = await record.get(domainId, rid);
|
||||
if (rdoc.tid) {
|
||||
const tdoc = await contest.get(domainId, rdoc.tid, rdoc.ttype);
|
||||
if (rdoc.contest) {
|
||||
const tdoc = await contest.get(domainId, rdoc.contest.tid, rdoc.contest.type);
|
||||
if (!this.canShowRecord(tdoc, true)) throw new PermissionError(rid);
|
||||
}
|
||||
if (rdoc.uid !== this.user.uid && !this.user.hasPerm(PERM.PERM_READ_RECORD_CODE)) {
|
||||
rdoc.code = null;
|
||||
}
|
||||
if (rdoc.type !== 'run') rdoc.stdout = rdoc.stderr = '';
|
||||
const [pdoc, udoc] = await Promise.all([
|
||||
problem.get(domainId, rdoc.pid, null),
|
||||
user.getById(domainId, rdoc.uid),
|
||||
@@ -83,8 +82,6 @@ class RecordDetailHandler extends RecordHandler {
|
||||
udoc,
|
||||
rdoc,
|
||||
pdoc,
|
||||
// TODO protect
|
||||
showStatus: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -134,7 +131,7 @@ class RecordMainConnectionHandler extends RecordConnectionHandler {
|
||||
|
||||
async onRecordChange(data) {
|
||||
const rdoc: Rdoc = data.value.rdoc;
|
||||
if (rdoc.tid && rdoc.tid.toString() !== this.tid) return;
|
||||
if (rdoc.contest && rdoc.contest.tid.toString() !== this.tid) return;
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [udoc, pdoc] = await Promise.all([
|
||||
user.getById(this.domainId, rdoc.uid),
|
||||
@@ -149,8 +146,8 @@ class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(Connecti
|
||||
@param('rid', Types.ObjectID)
|
||||
async prepare(domainId: string, rid: ObjectID) {
|
||||
const rdoc = await record.get(domainId, rid);
|
||||
if (rdoc.tid) {
|
||||
const tdoc = await contest.get(domainId, rdoc.tid, -1);
|
||||
if (rdoc.contest) {
|
||||
const tdoc = await contest.get(domainId, rdoc.contest.tid, -1);
|
||||
if (!this.canShowRecord(tdoc)) {
|
||||
this.close();
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user