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
75ebc1a746
commit
2554cf660a
34 files changed
+401
-150
No files matched your search
@@ -267,7 +267,7 @@ class ContestCreateHandler extends ContestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
function apply() {
|
||||
async function apply() {
|
||||
Route('/c', module.exports.ContestListHandler);
|
||||
Route('/c/:tid', module.exports.ContestDetailHandler);
|
||||
Route('/c/:tid/edit', module.exports.ContestEditHandler);
|
||||
@@ -278,7 +278,7 @@ function apply() {
|
||||
Route('/contest/create', module.exports.ContestCreateHandler);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.handler.contest = module.exports = {
|
||||
ContestListHandler,
|
||||
ContestDetailHandler,
|
||||
ContestEditHandler,
|
||||
|
||||
+15
-10
@@ -34,7 +34,9 @@ class DiscussionHandler extends Handler {
|
||||
if (drrid) {
|
||||
[, this.drrdoc] = await discussion.getTailReply(drid, drrid);
|
||||
if (!this.drrdoc) throw new DiscussionNotFoundError(drrid);
|
||||
if (this.drrdoc.parent !== this.drdoc._id) throw new DocumentNotFoundError(drid);
|
||||
if (this.drrdoc.parent !== this.drdoc._id) {
|
||||
throw new DocumentNotFoundError(drid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +62,11 @@ class DiscussionHandler extends Handler {
|
||||
|
||||
class DiscussionMainHandler extends DiscussionHandler {
|
||||
async get({ page = 1 }) {
|
||||
const [ddocs, dpcount] = await paginate(discussion.getMulti(), page, constants.DISCUSSION_PER_PAGE);
|
||||
const [ddocs, dpcount] = await paginate(
|
||||
discussion.getMulti(),
|
||||
page,
|
||||
constants.DISCUSSION_PER_PAGE,
|
||||
);
|
||||
const udict = await user.getList(ddocs.map((ddoc) => ddoc.owner));
|
||||
this.response.template = 'discussion_main_or_node.html';
|
||||
this.response.body = {
|
||||
@@ -114,12 +120,11 @@ class DiscussionCreateHandler extends DiscussionHandler {
|
||||
type, docId, title, content, highlight,
|
||||
}) {
|
||||
this.limitRate('add_discussion', 3600, 30);
|
||||
const flags = {};
|
||||
if (highlight) {
|
||||
this.checkPerm(PERM_HIGHLIGHT_DISCUSSION);
|
||||
flags.highlight = true;
|
||||
}
|
||||
const did = await discussion.add(type, docId, this.user._id, title, content, this.request.ip, flags);
|
||||
if (highlight) this.checkPerm(PERM_HIGHLIGHT_DISCUSSION);
|
||||
const did = await discussion.add(
|
||||
type, docId, this.user._id,
|
||||
title, content, this.request.ip, highlight,
|
||||
);
|
||||
this.response.body = { did };
|
||||
this.response.redirect = `/discuss/${did}`;
|
||||
}
|
||||
@@ -257,7 +262,7 @@ class DiscussionEditHandler extends DiscussionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
function apply() {
|
||||
async function apply() {
|
||||
Route('/discuss', module.exports.DiscussionMainHandler);
|
||||
Route('/discuss/:did', module.exports.DiscussionDetailHandler);
|
||||
Route('/discuss/:did/edit', module.exports.DiscussionEditHandler);
|
||||
@@ -268,7 +273,7 @@ function apply() {
|
||||
Route('/discuss/:type/:docId/create', module.exports.DiscussionCreateHandler);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
global.Hydro.handler.discussion = module.exports = {
|
||||
DiscussionMainHandler,
|
||||
DiscussionDetailHandler,
|
||||
DiscussionEditHandler,
|
||||
|
||||
@@ -171,11 +171,16 @@ class UserChangemailWithCodeHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
Route('/', HomeHandler);
|
||||
Route('/home/security', HomeSecurityHandler);
|
||||
Route('/home/changeMail/:code', UserChangemailWithCodeHandler);
|
||||
Route('/home/settings/:category', HomeSettingsHandler);
|
||||
async function apply() {
|
||||
Route('/', module.exports.HomeHandler);
|
||||
Route('/home/security', module.exports.HomeSecurityHandler);
|
||||
Route('/home/changeMail/:code', module.exports.UserChangemailWithCodeHandler);
|
||||
Route('/home/settings/:category', module.exports.HomeSettingsHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.home = module.exports = {
|
||||
HomeHandler, HomeSecurityHandler, HomeSettingsHandler, UserChangemailWithCodeHandler, apply,
|
||||
};
|
||||
/*
|
||||
@app.route('/home/messages', 'home_messages', global_route=True)
|
||||
class HomeMessagesHandler(base.OperationHandler):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
const problem = require('../model/problem');
|
||||
const { Route, Handler } = require('../service/server');
|
||||
const { PERM_CREATE_PROBLEM } = require('../permission');
|
||||
@@ -23,8 +22,10 @@ class ProblemImportHandler extends Handler {
|
||||
async post({
|
||||
url, pid, hidden, remoteType,
|
||||
}) {
|
||||
if (remoteType !== 'syzoj') throw new ValidationError('remoteType');
|
||||
const [pdoc, testdata] = await this.syzoj(url);
|
||||
if (typeof this[`from_${remoteType}`] !== 'function') {
|
||||
throw new ValidationError('remoteType');
|
||||
}
|
||||
const [pdoc, testdata] = await this[`from_${remoteType}`](url);
|
||||
if (pid) pdoc.pid = pid;
|
||||
if (hidden) pdoc.hidden = true;
|
||||
const _id = await problem.add(pdoc);
|
||||
@@ -39,6 +40,6 @@ async function apply() {
|
||||
Route('/problem/import', module.exports.ProblemImportHandler);
|
||||
}
|
||||
|
||||
global.Hydro['handler.import'] = module.exports = {
|
||||
global.Hydro.handler.import = module.exports = {
|
||||
ProblemImportHandler, apply,
|
||||
};
|
||||
@@ -183,5 +183,11 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
Route('/judge', JudgeHandler);
|
||||
Connection('/judge/conn', JudgeConnectionHandler);
|
||||
async function apply() {
|
||||
Route('/judge', module.exports.JudgeHandler);
|
||||
Connection('/judge/conn', module.exports.JudgeConnectionHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.judge = module.exports = {
|
||||
JudgeHandler, JudgeConnectionHandler, apply,
|
||||
};
|
||||
+18
-6
@@ -120,9 +120,21 @@ class ManageRoleHandler extends ManageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
Route('/manage', ManageMainHandler);
|
||||
Route('/manage/dashboard', ManageDashboardHandler);
|
||||
Route('/manage/edit', ManageEditHandler);
|
||||
Route('/manage/user', ManageUserHandler);
|
||||
Route('/manage/permission', ManagePermissionHandler);
|
||||
Route('/manage/role', ManageRoleHandler);
|
||||
async function apply() {
|
||||
Route('/manage', module.exports.ManageMainHandler);
|
||||
Route('/manage/dashboard', module.exports.ManageDashboardHandler);
|
||||
Route('/manage/edit', module.exports.ManageEditHandler);
|
||||
Route('/manage/user', module.exports.ManageUserHandler);
|
||||
Route('/manage/permission', module.exports.ManagePermissionHandler);
|
||||
Route('/manage/role', module.exports.ManageRoleHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.manage = module.exports = {
|
||||
ManageMainHandler,
|
||||
ManageDashboardHandler,
|
||||
ManageEditHandler,
|
||||
ManageUserHandler,
|
||||
ManagePermissionHandler,
|
||||
ManageRoleHandler,
|
||||
apply,
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
const { Route, Handler } = require('../service/server');
|
||||
const { NotFoundError } = require('../error');
|
||||
|
||||
class NotFoundHandler extends Handler {
|
||||
async prepare() {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
Route('/:param1', module.exports.NotFoundHandler);
|
||||
Route('/:param1/:param2', module.exports.NotFoundHandler);
|
||||
Route('/:param1/:param2/:param3', module.exports.NotFoundHandler);
|
||||
Route('/:param1/:param2/:param3/:param4', module.exports.NotFoundHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.notfound = module.exports = {
|
||||
NotFoundHandler, apply,
|
||||
};
|
||||
+39
-16
@@ -71,7 +71,9 @@ class ProblemDetailHandler extends ProblemHandler {
|
||||
this.uid = this.user._id;
|
||||
this.pid = pid;
|
||||
if (pid) this.pdoc = await problem.get(pid, this.uid);
|
||||
if (this.pdoc.hidden && this.pdoc.owner !== this.uid) this.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
|
||||
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 = {
|
||||
pdoc: this.pdoc,
|
||||
@@ -376,18 +378,39 @@ class ProblemCreateHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
Route('/p', ProblemHandler);
|
||||
Route('/problem/random', ProblemRandomHandler);
|
||||
Route('/p/:pid', ProblemDetailHandler);
|
||||
Route('/p/:pid/submit', ProblemSubmitHandler);
|
||||
Route('/p/:pid/pretest', ProblemPretestHandler);
|
||||
Route('/p/:pid/settings', ProblemSettingsHandler);
|
||||
Route('/p/:pid/statistics', ProblemStatisticsHandler);
|
||||
Route('/p/:pid/edit', ProblemEditHandler);
|
||||
Route('/p/:pid/upload', ProblemDataUploadHandler);
|
||||
Route('/p/:pid/data', ProblemDataDownloadHandler);
|
||||
Route('/p/:pid/solution', ProblemSolutionHandler);
|
||||
Route('/p/:pid/solution/:psid/raw', ProblemSolutionRawHandler);
|
||||
Route('/p/:pid/solution/:psid/:psrid/raw', ProblemSolutionReplyRawHandler);
|
||||
Route('/problem/create', ProblemCreateHandler);
|
||||
Connection('/p/:pid/pretest-conn', ProblemPretestConnectionHandler);
|
||||
async function apply() {
|
||||
Route('/p', module.exports.ProblemHandler);
|
||||
Route('/problem/random', module.exports.ProblemRandomHandler);
|
||||
Route('/p/:pid', module.exports.ProblemDetailHandler);
|
||||
Route('/p/:pid/submit', module.exports.ProblemSubmitHandler);
|
||||
Route('/p/:pid/pretest', module.exports.ProblemPretestHandler);
|
||||
Route('/p/:pid/settings', module.exports.ProblemSettingsHandler);
|
||||
Route('/p/:pid/statistics', module.exports.ProblemStatisticsHandler);
|
||||
Route('/p/:pid/edit', module.exports.ProblemEditHandler);
|
||||
Route('/p/:pid/upload', module.exports.ProblemDataUploadHandler);
|
||||
Route('/p/:pid/data', module.exports.ProblemDataDownloadHandler);
|
||||
Route('/p/:pid/solution', module.exports.ProblemSolutionHandler);
|
||||
Route('/p/:pid/solution/:psid/raw', module.exports.ProblemSolutionRawHandler);
|
||||
Route('/p/:pid/solution/:psid/:psrid/raw', module.exports.ProblemSolutionReplyRawHandler);
|
||||
Route('/problem/create', module.exports.ProblemCreateHandler);
|
||||
Connection('/p/:pid/pretest-conn', module.exports.ProblemPretestConnectionHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.problem = module.exports = {
|
||||
ProblemHandler,
|
||||
ProblemRandomHandler,
|
||||
ProblemDetailHandler,
|
||||
ProblemSubmitHandler,
|
||||
ProblemPretestHandler,
|
||||
ProblemSettingsHandler,
|
||||
ProblemStatisticsHandler,
|
||||
ProblemEditHandler,
|
||||
ProblemDataUploadHandler,
|
||||
ProblemDataDownloadHandler,
|
||||
ProblemSolutionHandler,
|
||||
ProblemSolutionRawHandler,
|
||||
ProblemSolutionReplyRawHandler,
|
||||
ProblemCreateHandler,
|
||||
ProblemPretestConnectionHandler,
|
||||
apply,
|
||||
};
|
||||
+25
-13
@@ -34,18 +34,16 @@ class RecordListHandler extends Handler {
|
||||
for (const pdoc of plist) {
|
||||
pdict[pdoc._id] = pdoc;
|
||||
}
|
||||
const path = [
|
||||
['Hydro', '/'],
|
||||
['record_main', null],
|
||||
];
|
||||
this.response.body = {
|
||||
path: [
|
||||
['Hydro', '/'],
|
||||
['record_main', null],
|
||||
],
|
||||
page,
|
||||
rdocs,
|
||||
pdict,
|
||||
udict,
|
||||
path, page, rdocs, pdict, udict,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class RecordDetailHandler extends Handler {
|
||||
async get({ rid }) {
|
||||
this.response.template = 'record_detail.html';
|
||||
@@ -66,6 +64,7 @@ class RecordDetailHandler extends Handler {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class RecordRejudgeHandler extends Handler {
|
||||
async post({ rid }) {
|
||||
this.checkPerm(PERM_REJUDGE);
|
||||
@@ -77,6 +76,7 @@ class RecordRejudgeHandler extends Handler {
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
|
||||
class RecordConnectionHandler extends ConnectionHandler {
|
||||
async prepare() {
|
||||
bus.subscribe(['record_change'], this.onRecordChange);
|
||||
@@ -102,6 +102,7 @@ class RecordConnectionHandler extends ConnectionHandler {
|
||||
this.send({ html: await this.renderHTML('record_main_tr.html', { rdoc, udoc, pdoc }) });
|
||||
}
|
||||
}
|
||||
|
||||
class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(ConnectionHandler) {
|
||||
async prepare({ rid }) {
|
||||
const rdoc = await record.get(rid);
|
||||
@@ -131,8 +132,19 @@ class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(Connecti
|
||||
}
|
||||
}
|
||||
|
||||
Route('/r', RecordListHandler);
|
||||
Route('/r/:rid', RecordDetailHandler);
|
||||
Route('/r/:rid/rejudge', RecordRejudgeHandler);
|
||||
Connection('/record-conn', RecordConnectionHandler);
|
||||
Connection('/record-detail-conn', RecordDetailConnectionHandler);
|
||||
async function apply() {
|
||||
Route('/r', module.exports.RecordListHandler);
|
||||
Route('/r/:rid', module.exports.RecordDetailHandler);
|
||||
Route('/r/:rid/rejudge', module.exports.RecordRejudgeHandler);
|
||||
Connection('/record-conn', module.exports.RecordConnectionHandler);
|
||||
Connection('/record-detail-conn', module.exports.RecordDetailConnectionHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.record = module.exports = {
|
||||
RecordListHandler,
|
||||
RecordDetailHandler,
|
||||
RecordRejudgeHandler,
|
||||
RecordConnectionHandler,
|
||||
RecordDetailConnectionHandler,
|
||||
apply,
|
||||
};
|
||||
@@ -237,7 +237,17 @@ class TrainingEditHandler extends TrainingHandler {
|
||||
}
|
||||
}
|
||||
|
||||
Route('/t', TrainingMainHandler);
|
||||
Route('/t/:tid', TrainingDetailHandler);
|
||||
Route('/t/:tid/edit', TrainingEditHandler);
|
||||
Route('/training/create', TrainingCreateHandler);
|
||||
async function apply() {
|
||||
Route('/t', module.exports.TrainingMainHandler);
|
||||
Route('/t/:tid', module.exports.TrainingDetailHandler);
|
||||
Route('/t/:tid/edit', module.exports.TrainingEditHandler);
|
||||
Route('/training/create', module.exports.TrainingCreateHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.training = module.exports = {
|
||||
TrainingMainHandler,
|
||||
TrainingDetailHandler,
|
||||
TrainingEditHandler,
|
||||
TrainingCreateHandler,
|
||||
apply,
|
||||
};
|
||||
+22
-8
@@ -181,11 +181,25 @@ class UserSearchHandler extends Handler {
|
||||
}
|
||||
}
|
||||
|
||||
Route('/login', UserLoginHandler);
|
||||
Route('/register', UserRegisterHandler);
|
||||
Route('/register/:code', UserRegisterWithCodeHandler);
|
||||
Route('/logout', UserLogoutHandler);
|
||||
Route('/lostpass', UserLostPassHandler);
|
||||
Route('/lostpass/:code', UserLostPassWithCodeHandler);
|
||||
Route('/user/search', UserSearchHandler);
|
||||
Route('/user/:uid', UserDetailHandler);
|
||||
async function apply() {
|
||||
Route('/login', module.exports.UserLoginHandler);
|
||||
Route('/register', module.exports.UserRegisterHandler);
|
||||
Route('/register/:code', module.exports.UserRegisterWithCodeHandler);
|
||||
Route('/logout', module.exports.UserLogoutHandler);
|
||||
Route('/lostpass', module.exports.UserLostPassHandler);
|
||||
Route('/lostpass/:code', module.exports.UserLostPassWithCodeHandler);
|
||||
Route('/user/search', module.exports.UserSearchHandler);
|
||||
Route('/user/:uid', module.exports.UserDetailHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.user = module.exports = {
|
||||
UserLoginHandler,
|
||||
UserRegisterHandler,
|
||||
UserRegisterWithCodeHandler,
|
||||
UserLogoutHandler,
|
||||
UserLostPassHandler,
|
||||
UserLostPassWithCodeHandler,
|
||||
UserSearchHandler,
|
||||
UserDetailHandler,
|
||||
apply,
|
||||
};
|
||||
Reference in new issue
Block a user