mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
添加部分注释,修复一些功能
This commit is contained in:
1 parent
f40e4e2c74
commit
d3e36fcb6c
32 files changed
+320
-174
No files matched your search
@@ -250,15 +250,12 @@ class ContestCreateHandler extends ContestHandler {
|
||||
}
|
||||
async post({ title, content, rule, beginAtDate, beginAtTime, duration, pids }) {
|
||||
let beginAt, endAt;
|
||||
console.log(beginAtDate, beginAtTime);
|
||||
try {
|
||||
beginAt = new Date(Date.parse(`${beginAtDate} ${beginAtTime.replace('-', ':')}`));
|
||||
console.log(beginAt, duration);
|
||||
} catch (e) {
|
||||
throw new ValidationError('beginAtDate', 'beginAtTime');
|
||||
}
|
||||
endAt = new Date(beginAt.getTime() + duration * 3600 * 1000);
|
||||
console.log(endAt);
|
||||
if (beginAt >= endAt) throw new ValidationError('duration');
|
||||
await this.verifyProblems(pids);
|
||||
let tid = await contest.add(title, content, this.user._id, rule, beginAt, endAt, pids);
|
||||
|
||||
@@ -56,10 +56,12 @@ async function end(body) {
|
||||
}
|
||||
|
||||
class JudgeHandler extends Handler {
|
||||
async prepare(){
|
||||
async prepare() {
|
||||
this.checkPerm(PERM_JUDGE);
|
||||
}
|
||||
async get() {
|
||||
async get({ check = false }) {
|
||||
this.response.body = {};
|
||||
if (check) return;
|
||||
let rid = await queue.get('judge', false);
|
||||
if (rid) {
|
||||
let rdoc = await record.get(rid);
|
||||
@@ -74,7 +76,6 @@ class JudgeHandler extends Handler {
|
||||
};
|
||||
this.response.body = { task };
|
||||
}
|
||||
else this.response.body = {};
|
||||
}
|
||||
async post_next() {
|
||||
await next(this.request.body);
|
||||
|
||||
@@ -56,7 +56,7 @@ class ProblemDetailHandler extends ProblemHandler {
|
||||
this.response.template = 'problem_detail.html';
|
||||
this.uid = this.user._id;
|
||||
this.pid = pid;
|
||||
if (pid) this.pdoc = await problem.get(this);
|
||||
if (pid) this.pdoc = await problem.get(this.pid, this.uid);
|
||||
if (this.pdoc.hidden && this.pdoc.owner != this.uid) this.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
|
||||
if (this.pdoc) this.udoc = await user.getById(this.pdoc.owner);
|
||||
this.response.body = {
|
||||
@@ -115,7 +115,7 @@ class ProblemManageHandler extends ProblemDetailHandler {
|
||||
class ProblemSettingsHandler extends ProblemManageHandler {
|
||||
async get() {
|
||||
this.response.template = 'problem_settings.html';
|
||||
this.ctx.body.path = [
|
||||
this.response.body.path = [
|
||||
['Hydro', '/'],
|
||||
['problem_main', '/p'],
|
||||
[this.pdoc.title, `/p/${this.pid}`, true],
|
||||
@@ -141,15 +141,14 @@ class ProblemEditHandler extends ProblemManageHandler {
|
||||
}
|
||||
async post({ title, content }) {
|
||||
let pid = validator.checkPid(this.request.body.pid);
|
||||
let pdoc = await problem.get({ pid: this.params.pid });
|
||||
let pdoc = await problem.get(this.params.pid);
|
||||
await problem.edit(pdoc._id, { title, content, pid });
|
||||
this.response.redirect = `/p/${pid}`;
|
||||
}
|
||||
}
|
||||
|
||||
class ProblemDataUploadHandler extends ProblemManageHandler {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
async prepare(){
|
||||
this.response.template = 'problem_upload.html';
|
||||
}
|
||||
async get() {
|
||||
|
||||
@@ -17,7 +17,7 @@ class RecordListHandler extends Handler {
|
||||
let pdict = {}, udict = {};
|
||||
for (let rdoc of rdocs) {
|
||||
udict[rdoc.uid] = await user.getById(rdoc.uid);
|
||||
pdict[rdoc.pid] = await problem.get({ pid: rdoc.pid, uid: this.user._id });
|
||||
pdict[rdoc.pid] = await problem.get(rdoc.pid, this.user._id);
|
||||
}
|
||||
this.response.body = {
|
||||
path: [
|
||||
@@ -51,7 +51,7 @@ class RecordRejudgeHandler extends Handler {
|
||||
await record.reset(rid);
|
||||
await queue.push('judge', rid);
|
||||
}
|
||||
this.response.back();
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
class RecordConnectionHandler extends ConnectionHandler {
|
||||
@@ -70,7 +70,7 @@ class RecordConnectionHandler extends ConnectionHandler {
|
||||
async onRecordChange(data) {
|
||||
let rdoc = data.value;
|
||||
if (rdoc.tid && rdoc.tid.toString() != this.tid) return;
|
||||
let [udoc, pdoc] = await Promise.all([user.getById(rdoc.uid), problem.get({ pid: rdoc.pid })]);
|
||||
let [udoc, pdoc] = await Promise.all([user.getById(rdoc.uid), problem.getById(rdoc.pid)]);
|
||||
if (pdoc.hidden && !this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null;
|
||||
this.send({ html: await this.renderHTML('record_main_tr.html', { rdoc, udoc, pdoc }) });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user