mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
markdown语法增强,错误修复
This commit is contained in:
1 parent
4b3c10b4eb
commit
a29b801e72
22 files changed
+311
-200
No files matched your search
+12
-10
@@ -147,25 +147,27 @@ class ContestEditHandler extends ContestDetailHandler {
|
||||
}
|
||||
|
||||
async post({
|
||||
domainId, beginAtDate, beginAtTime, duration, title, content, rule, pids,
|
||||
domainId, beginAtDate, beginAtTime, duration, title, content, rule, pids, rated = false,
|
||||
}) {
|
||||
let beginAt;
|
||||
try {
|
||||
beginAt = moment.tz(`${beginAtDate} ${beginAtTime}`, this.uset.timeZone);
|
||||
beginAt = moment.tz(`${beginAtDate} ${beginAtTime}`, this.user.timeZone);
|
||||
} catch (e) {
|
||||
throw new ValidationError('beginAtDate', 'beginAtTime');
|
||||
}
|
||||
const endAt = beginAt.add(duration, 'hours').toDate();
|
||||
const endAt = beginAt.clone().add(duration, 'hours').toDate();
|
||||
if (beginAt.isSameOrAfter(endAt)) throw new ValidationError('duration');
|
||||
beginAt = beginAt.toDate();
|
||||
pids = await this.verifyProblems(domainId, pids);
|
||||
await contest.edit(domainId, this.tdoc.docId, title, content, rule, beginAt, endAt, pids);
|
||||
await contest.edit(domainId, this.tdoc.docId, {
|
||||
title, content, rule, beginAt, endAt, pids, rated,
|
||||
});
|
||||
if (this.tdoc.beginAt !== beginAt || this.tdoc.endAt !== endAt
|
||||
|| Array.isDiff(this.tdoc.pids, pids) || this.tdoc.rule !== rule) {
|
||||
await contest.recalcStatus(this.tdoc.docId);
|
||||
}
|
||||
if (this.preferJson) this.response.body = { tid: this.tdoc.docId };
|
||||
else this.response.redirect = `/c/${this.tdoc.docId}`;
|
||||
this.response.body = { tid: this.tdoc.docId };
|
||||
this.response.redirect = this.url('contest_detail', { tid: this.tdoc.docId });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,10 +253,10 @@ class ContestProblemSubmitHandler extends ContestProblemHandler {
|
||||
await contest.updateStatus(domainId, this.tdoc.docId, this.user._id, rid, this.pdoc.docId);
|
||||
if (!this.canShowRecord(this.tdoc)) {
|
||||
this.response.body = { tid };
|
||||
this.response.redirect = `/c/${tid}`;
|
||||
this.response.redirect = this.url('contest_detail', { tid });
|
||||
} else {
|
||||
this.response.body = { rid };
|
||||
this.response.redirect = `/r/${rid}`;
|
||||
this.response.redirect = this.url('record_detail', { rid });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -292,14 +294,14 @@ class ContestCreateHandler extends ContestHandler {
|
||||
} catch (e) {
|
||||
throw new ValidationError('beginAtDate', 'beginAtTime');
|
||||
}
|
||||
const endAt = beginAt.add(duration, 'hours');
|
||||
const endAt = beginAt.clone().add(duration, 'hours');
|
||||
pids = await this.verifyProblems(domainId, pids);
|
||||
const tid = await contest.add(
|
||||
domainId, title, content,
|
||||
this.user._id, rule, beginAt, endAt, pids, rated,
|
||||
);
|
||||
this.response.body = { tid };
|
||||
this.response.redirect = `/c/${tid}`;
|
||||
this.response.redirect = this.url('contest_detail', { tid });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
|
||||
class HomeworkCreateHandler extends HomeworkHandler {
|
||||
async get() {
|
||||
const beginAt = moment().add(1, 'day');
|
||||
const penaltySince = beginAt.add(7, 'days');
|
||||
const penaltySince = beginAt.clone().add(7, 'days');
|
||||
const path = [
|
||||
['Hydro', 'homepage'],
|
||||
['homework_main', 'homework_main'],
|
||||
@@ -212,7 +212,7 @@ class HomeworkCreateHandler extends HomeworkHandler {
|
||||
} catch (e) {
|
||||
throw new ValidationError('endAtDate', 'endAtTime');
|
||||
}
|
||||
const endAt = penaltySince.add(extensionDays, 'days');
|
||||
const endAt = penaltySince.clone().add(extensionDays, 'days');
|
||||
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
|
||||
if (penaltySince.isAfter(endAt)) throw new ValidationError('extensionDays');
|
||||
penaltySince = penaltySince.toDate();
|
||||
@@ -273,7 +273,7 @@ class HomeworkEditHandler extends HomeworkHandler {
|
||||
} catch (e) {
|
||||
throw new ValidationError('endAtDate', 'endAtTime');
|
||||
}
|
||||
let endAt = penaltySince.add(extensionDays, 'days');
|
||||
let endAt = penaltySince.clone().add(extensionDays, 'days');
|
||||
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
|
||||
await this.verifyProblems(domainId, pids);
|
||||
beginAt = beginAt.toDate();
|
||||
|
||||
+15
-10
@@ -38,14 +38,17 @@ async function next(body) {
|
||||
const $set = {};
|
||||
const $push = {};
|
||||
if (body.case) {
|
||||
body.case.memory = body.case.memory_kb;
|
||||
body.case.time = body.case.time_ms;
|
||||
rdoc.testCases.push(body.case);
|
||||
$push.testCases = body.case;
|
||||
const c = {};
|
||||
c.memory = body.case.memory_kb || body.case.memory;
|
||||
c.time = body.case.time_ms || body.case.time;
|
||||
c.judgeText = body.case.judge_text || body.case.judgeText || body.case.message;
|
||||
c.status = body.case.status;
|
||||
rdoc.testCases.push(c);
|
||||
$push.testCases = c;
|
||||
}
|
||||
if (body.judge_text) {
|
||||
rdoc.judgeTexts.push(body.judge_text);
|
||||
$push.judgeTexts = body.judge_text;
|
||||
if (body.judge_text || body.message) {
|
||||
rdoc.judgeTexts.push(body.judge_text || body.message);
|
||||
$push.judgeTexts = body.judge_text || body.message;
|
||||
}
|
||||
if (body.compiler_text) {
|
||||
rdoc.compilerTexts.push(body.compiler_text);
|
||||
@@ -53,8 +56,9 @@ async function next(body) {
|
||||
}
|
||||
if (body.status) $set.status = body.status;
|
||||
if (body.score) $set.score = body.score;
|
||||
if (body.time_ms) $set.time = body.time_ms;
|
||||
if (body.memory_kb) $set.memory = body.memory_kb;
|
||||
if (body.time_ms) $set.time = body.time_ms || body.time;
|
||||
if (body.memory_kb) $set.memory = body.memory_kb || body.memory;
|
||||
if (body.progress) $set.progress = body.progress;
|
||||
rdoc = await record.update(body.domainId, body.rid, $set, $push);
|
||||
bus.publish('record_change', rdoc);
|
||||
}
|
||||
@@ -63,6 +67,7 @@ async function end(body) {
|
||||
let rdoc = await record.get(body.domainId, body.rid);
|
||||
const $set = {};
|
||||
const $push = {};
|
||||
const $unset = { progress: '' };
|
||||
if (body.judge_text) {
|
||||
rdoc.judgeTexts.push(body.judge_text);
|
||||
$push.judgeTexts = body.judge_text;
|
||||
@@ -77,7 +82,7 @@ async function end(body) {
|
||||
if (body.memory_kb) $set.memory = body.memory_kb;
|
||||
$set.judgeAt = new Date();
|
||||
$set.judger = body.judger;
|
||||
rdoc = await record.update(body.domainId, body.rid, $set, $push);
|
||||
rdoc = await record.update(body.domainId, body.rid, $set, $push, $unset);
|
||||
await _postJudge(rdoc);
|
||||
rdoc = await record.update(body.domainId, body.rid, $set, $push);
|
||||
}
|
||||
|
||||
+44
-3
@@ -1,5 +1,8 @@
|
||||
const setting = require('../model/setting');
|
||||
const system = require('../model/system');
|
||||
const { STATUS } = require('../model/builtin');
|
||||
const record = require('../model/record');
|
||||
const judge = require('./judge');
|
||||
const { Route, Handler } = require('../service/server');
|
||||
const hpm = require('../lib/hpm');
|
||||
const loader = require('../loader');
|
||||
@@ -56,11 +59,49 @@ class SystemScriptHandler extends SystemHandler {
|
||||
this.response.body.path.push(['manage_script', null]);
|
||||
}
|
||||
|
||||
async post({ id, args = '{}' }) {
|
||||
async post({ domainId, id, args = '{}' }) {
|
||||
args = JSON.parse(args);
|
||||
// TODO Do not use console.log
|
||||
await global.Hydro.script[id].run(args, console.log);
|
||||
this.back();
|
||||
const rid = await record.add(domainId, {
|
||||
pid: id,
|
||||
uid: this.user._id,
|
||||
lang: null,
|
||||
code: null,
|
||||
status: STATUS.STATUS_JUDGING,
|
||||
}, false);
|
||||
async function report(data) {
|
||||
judge.next({ domainId, rid, ...data });
|
||||
}
|
||||
setTimeout(() => {
|
||||
const start = new Date().getTime();
|
||||
global.Hydro.script[id].run(args, report)
|
||||
.then((ret) => {
|
||||
const time = new Date().getTime() - start;
|
||||
judge.end({
|
||||
domainId,
|
||||
rid,
|
||||
status: STATUS.STATUS_ACCEPTED,
|
||||
judge_text: ret,
|
||||
judger: 1,
|
||||
time_ms: time,
|
||||
memory_kb: 0,
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
const time = new Date().getTime() - start;
|
||||
judge.end({
|
||||
domainId,
|
||||
rid,
|
||||
status: STATUS.STATUS_SYSTEM_ERROR,
|
||||
judge_text: `${err}\n${err.stack}`,
|
||||
judger: 1,
|
||||
time_ms: time,
|
||||
memory_kb: 0,
|
||||
});
|
||||
});
|
||||
}, 500);
|
||||
this.response.body = { rid };
|
||||
this.response.redirect = this.url('record_main', { rid });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-9
@@ -5,6 +5,7 @@ const record = require('../model/record');
|
||||
const contest = require('../model/contest');
|
||||
const system = require('../model/system');
|
||||
const user = require('../model/user');
|
||||
const paginate = require('../lib/paginate');
|
||||
const bus = require('../service/bus');
|
||||
const {
|
||||
Route, Handler, Connection, ConnectionHandler,
|
||||
@@ -25,7 +26,11 @@ class RecordListHandler extends RecordHandler {
|
||||
];
|
||||
}
|
||||
if (pid) q.pid = pid;
|
||||
const rdocs = await record.getMany(domainId, q, { _id: -1 }, page, await system.get('RECORD_PER_PAGE'));
|
||||
const [rdocs] = await paginate(
|
||||
record.getMulti(domainId, q).sort('_id', -1),
|
||||
page,
|
||||
await system.get('RECORD_PER_PAGE'),
|
||||
);
|
||||
const [udict, pdict] = await Promise.all([
|
||||
user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)),
|
||||
problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), false),
|
||||
@@ -59,7 +64,7 @@ class RecordDetailHandler extends RecordHandler {
|
||||
rdoc.code = null;
|
||||
}
|
||||
const [pdoc, udoc] = await Promise.all([
|
||||
problem.get(domainId, rdoc.pid),
|
||||
problem.get(domainId, rdoc.pid, null, false),
|
||||
user.getById(domainId, rdoc.uid),
|
||||
]);
|
||||
this.response.body = {
|
||||
@@ -101,13 +106,13 @@ class RecordMainConnectionHandler extends RecordConnectionHandler {
|
||||
}
|
||||
|
||||
async message(msg) {
|
||||
const rdocs = await record.getMany(
|
||||
this.domainId,
|
||||
{ _id: { $in: msg.rids } },
|
||||
{ _id: -1 }, 1, 100,
|
||||
);
|
||||
for (const rdoc of rdocs) {
|
||||
this.onRecordChange({ value: rdoc });
|
||||
if (msg.rids instanceof Array) {
|
||||
const rdocs = await record.getMulti(
|
||||
this.domainId, { _id: { $in: msg.rids } },
|
||||
).toArray();
|
||||
for (const rdoc of rdocs) {
|
||||
this.onRecordChange({ value: rdoc });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user