mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
主页
This commit is contained in:
1 parent
ce3d11b999
commit
b1153b641a
13 files changed
+163
-42
No files matched your search
+52
-1
@@ -1,8 +1,59 @@
|
||||
const { Route, Handler } = require('../service/server');
|
||||
const contest = require('../model/contest');
|
||||
const user = require('../model/user');
|
||||
const training = require('../model/training');
|
||||
const { PERM_VIEW_TRAINING, PERM_VIEW_CONTEST, PERM_VIEW_DISCUSSION } = require('../permission');
|
||||
const { CONTESTS_ON_MAIN, TRAININGS_ON_MAIN, DISCUSSIONS_ON_MAIN } = require('../options').constants;
|
||||
|
||||
class HomeHandler extends Handler {
|
||||
async contest() {
|
||||
if (this.user.hasPerm(PERM_VIEW_CONTEST)) {
|
||||
const tdocs = await contest.getMulti()
|
||||
.limit(CONTESTS_ON_MAIN)
|
||||
.toArray();
|
||||
const tsdict = await contest.getListStatus(
|
||||
this.user._id, tdocs.map((tdoc) => tdoc._id),
|
||||
);
|
||||
return [tdocs, tsdict];
|
||||
}
|
||||
return [[], {}];
|
||||
}
|
||||
|
||||
async training() {
|
||||
if (this.user.hasPerm(PERM_VIEW_TRAINING)) {
|
||||
const tdocs = await training.getMulti()
|
||||
.sort('_id', 1)
|
||||
.limit(TRAININGS_ON_MAIN)
|
||||
.toArray();
|
||||
const tsdict = await training.getListStatus(
|
||||
this.user._id, tdocs.map((tdoc) => tdoc._id),
|
||||
);
|
||||
return [tdocs, tsdict];
|
||||
}
|
||||
return [[], {}];
|
||||
}
|
||||
|
||||
async discussion() {
|
||||
// TODO(masnn)
|
||||
// if (this.user.hasPerm(PERM_VIEW_DISCUSSION)) {
|
||||
// const ddocs = await discussion.getMulti()
|
||||
// .limit(DISCUSSIONS_ON_MAIN)
|
||||
// .toArray();
|
||||
// const vndict = await discussion.getListVnodes(map(discussion.node_id, ddocs));
|
||||
// return [ddocs, vndict];
|
||||
// }
|
||||
return [[], {}];
|
||||
}
|
||||
|
||||
async get() {
|
||||
this.response.body = {};
|
||||
const [[tdocs, tsdict], [trdocs, trsdict], [ddocs, vndict]] = await Promise.all([
|
||||
this.contest(), this.training(), this.discussion(),
|
||||
]);
|
||||
const udict = await user.getList(ddocs.map((ddoc) => ddoc.owner));
|
||||
this.response.template = 'main.html';
|
||||
this.response.body = {
|
||||
tdocs, tsdict, trdocs, trsdict, ddocs, vndict, udict,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+38
-9
@@ -1,6 +1,9 @@
|
||||
const { PERM_JUDGE } = require('../permission');
|
||||
const record = require('../model/record');
|
||||
const problem = require('../model/problem');
|
||||
const builtin = require('../model/builtin');
|
||||
const contest = require('../model/contest');
|
||||
const user = require('../model/user');
|
||||
const bus = require('../service/bus');
|
||||
const queue = require('../service/queue');
|
||||
const {
|
||||
@@ -9,42 +12,66 @@ const {
|
||||
|
||||
queue.assert('judge');
|
||||
|
||||
async function _postJudge(rdoc) {
|
||||
const accept = rdoc.status === builtin.STATUS_ACCEPTED;
|
||||
bus.publish('record_change', rdoc);
|
||||
const tasks = [];
|
||||
if (rdoc.tid) {
|
||||
tasks.push(
|
||||
contest.updateStatus(rdoc.tid, rdoc.uid, rdoc._id, rdoc.pid, accept, rdoc.score),
|
||||
);
|
||||
}
|
||||
if (!rdoc.rejudged) {
|
||||
if (await problem.updateStatus(rdoc.pid, rdoc.uid, rdoc._id, rdoc.status)) {
|
||||
if (accept) {
|
||||
tasks.push(
|
||||
problem.inc(rdoc.pid, 'nAccept', 1),
|
||||
user.inc(rdoc.uid, 'nAccept', 1),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
async function next(body) {
|
||||
let rdoc = await record.get(body.rid);
|
||||
const $set = {};
|
||||
const $push = {};
|
||||
if (body.case) {
|
||||
rdoc.testCases.push(body.case);
|
||||
$set.testCases = rdoc.testCases;
|
||||
$push.testCases = body.case;
|
||||
}
|
||||
if (body.judge_text) {
|
||||
rdoc.judgeTexts.push(body.judge_text);
|
||||
$set.judgeTexts = rdoc.judgeTexts;
|
||||
$push.judgeTexts = body.judge_text;
|
||||
}
|
||||
if (body.compiler_text) {
|
||||
rdoc.compilerTexts.push(body.compiler_text);
|
||||
$set.compilerTexts = rdoc.compilerTexts;
|
||||
$push.compilerTexts = body.compiler_text;
|
||||
}
|
||||
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;
|
||||
rdoc = await record.update(body.rid, $set);
|
||||
rdoc = await record.update(body.rid, $set, $push);
|
||||
bus.publish('record_change', rdoc);
|
||||
}
|
||||
async function end(body) {
|
||||
let rdoc = await record.get(body.rid);
|
||||
const $set = {};
|
||||
const $push = {};
|
||||
if (body.case) {
|
||||
rdoc.testCases.push(body.case);
|
||||
$set.testCases = rdoc.testCases;
|
||||
$push.testCases = body.case;
|
||||
}
|
||||
if (body.judge_text) {
|
||||
rdoc.judgeTexts.push(body.judge_text);
|
||||
$set.judgeTexts = rdoc.judgeTexts;
|
||||
$push.judgeTexts = body.judge_text;
|
||||
}
|
||||
if (body.compiler_text) {
|
||||
rdoc.compilerTexts.push(body.compiler_text);
|
||||
$set.compilerTexts = rdoc.compilerTexts;
|
||||
$push.compilerTexts = body.compiler_text;
|
||||
}
|
||||
if (body.status) $set.status = body.status;
|
||||
if (body.score) $set.score = body.score;
|
||||
@@ -52,8 +79,9 @@ 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.rid, $set);
|
||||
bus.publish('record_change', rdoc);
|
||||
rdoc = await record.update(body.rid, $set, $push);
|
||||
await _postJudge(rdoc);
|
||||
rdoc = await record.update(body.rid, $set, $push);
|
||||
}
|
||||
|
||||
class JudgeHandler extends Handler {
|
||||
@@ -87,6 +115,7 @@ class JudgeHandler extends Handler {
|
||||
}
|
||||
|
||||
async postEnd() {
|
||||
this.request.body.judger = this.user._id;
|
||||
await end(this.request.body);
|
||||
this.response.body = {};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ const {
|
||||
PERM_CREATE_PROBLEM, PERM_READ_PROBLEM_DATA, PERM_EDIT_PROBLEM,
|
||||
PERM_JUDGE, PERM_VIEW_PROBLEM_SOLUTION, PERM_CREATE_PROBLEM_SOLUTION,
|
||||
PERM_EDIT_PROBLEM_SOLUTION, PERM_DELETE_PROBLEM_SOLUTION, PERM_EDIT_PROBLEM_SOLUTION_REPLY,
|
||||
PERM_REPLY_PROBLEM_SOLUTION,
|
||||
PERM_REPLY_PROBLEM_SOLUTION, PERM_LOGGEDIN,
|
||||
} = require('../permission');
|
||||
|
||||
queue.assert('judge');
|
||||
@@ -32,9 +32,13 @@ class ProblemHandler extends Handler {
|
||||
async get({ page = 1, category = null }) {
|
||||
this.response.template = 'problem_main.html';
|
||||
const q = {};
|
||||
let psdict = {};
|
||||
if (category) q.category = category;
|
||||
if (!this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) q.hidden = false;
|
||||
const pdocs = await problem.getMany(q, { pid: 1 }, page, constants.PROBLEM_PER_PAGE);
|
||||
if (this.user.hasPerm(PERM_LOGGEDIN)) {
|
||||
psdict = await problem.getListStatus(this.user._id, pdocs.map((pdoc) => pdoc._id));
|
||||
}
|
||||
this.response.body = {
|
||||
path: [
|
||||
['Hydro', '/'],
|
||||
@@ -42,6 +46,7 @@ class ProblemHandler extends Handler {
|
||||
],
|
||||
page,
|
||||
pdocs,
|
||||
psdict,
|
||||
category: '',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,12 +54,14 @@ class RecordDetailHandler extends Handler {
|
||||
if (rdoc.uid !== this.user.uid && !this.user.hasPerm(PERM_READ_RECORD_CODE)) {
|
||||
rdoc.code = null;
|
||||
}
|
||||
const pdoc = await problem.getById(rdoc.pid);
|
||||
this.response.body = {
|
||||
path: [
|
||||
['Hydro', '/'],
|
||||
['record_detail', null],
|
||||
],
|
||||
rdoc,
|
||||
pdoc,
|
||||
show_status: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class TrainingDetailHandler extends TrainingHandler {
|
||||
for (const pid in psdict) {
|
||||
const psdoc = psdict[pid];
|
||||
if (psdoc.status) {
|
||||
if (psdoc.status === builtin.status.STATUS_ACCEPTED) donePids.add(pid);
|
||||
if (psdoc.status === builtin.STATUS_ACCEPTED) donePids.add(pid);
|
||||
else progPids.add(pid);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user