mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
一些优化
优化 Date.prototype.format 修复题目分类解析错误的问题 Interface Tdoc X-Forwarded-For 支持
This commit is contained in:
1 parent
1722fbfaca
commit
82c193b5ee
19 files changed
+289
-182
No files matched your search
@@ -155,8 +155,8 @@ class ContestEditHandler extends ContestHandler {
|
||||
duration,
|
||||
path,
|
||||
pids: this.tdoc.pids.join(','),
|
||||
date_text: `${dt.getFullYear()}-${dt.getMonth() + 1}-${dt.getDate()}`,
|
||||
time_text: `${dt.getHours()}:${dt.getMinutes()}`,
|
||||
date_text: dt.format('%Y-%m-%d'),
|
||||
time_text: dt.format('%H:%M'),
|
||||
page_name: 'contest_edit',
|
||||
};
|
||||
}
|
||||
@@ -337,8 +337,8 @@ class ContestCreateHandler extends ContestHandler {
|
||||
rules,
|
||||
path,
|
||||
page_name: 'contest_create',
|
||||
date_text: `${dt.getFullYear()}-${dt.getMonth() + 1}-${dt.getDate()}`,
|
||||
time_text: `${dt.getHours()}:${dt.getMinutes()}`,
|
||||
date_text: dt.format('%Y-%m-%d'),
|
||||
time_text: dt.format('%M:%S'),
|
||||
pids: '1000, 1001',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,6 +21,14 @@ export const typeMapper = {
|
||||
};
|
||||
|
||||
class DiscussionHandler extends Handler {
|
||||
ddoc?: any;
|
||||
|
||||
drdoc?: any;
|
||||
|
||||
drrdoc?: any;
|
||||
|
||||
vnode?: any;
|
||||
|
||||
async _prepare({
|
||||
domainId, type, name, did, drid, drrid,
|
||||
}) {
|
||||
|
||||
@@ -60,6 +60,8 @@ class DomainCreateHandler extends Handler {
|
||||
}
|
||||
|
||||
class ManageHandler extends Handler {
|
||||
domain: any;
|
||||
|
||||
async prepare({ domainId }) {
|
||||
this.checkPerm(PERM.PERM_EDIT_DOMAIN);
|
||||
this.domain = await domain.get(domainId);
|
||||
|
||||
@@ -147,10 +147,10 @@ class HomeSecurityHandler extends Handler {
|
||||
const [code] = await token.add(
|
||||
token.TYPE_CHANGEMAIL,
|
||||
await system.get('changemail_token_expire_seconds'),
|
||||
{ uid: this.udoc._id, mail },
|
||||
{ uid: this.user._id, mail },
|
||||
);
|
||||
await mail.sendMail(mail, 'Change Email', 'user_changemail_mail.html', {
|
||||
url: this.url('user_changemail_with_code', { code }), uname: this.udoc.uname,
|
||||
url: this.url('user_changemail_with_code', { code }), uname: this.user.uname,
|
||||
});
|
||||
this.response.template = 'user_changemail_mail_sent.html';
|
||||
}
|
||||
|
||||
@@ -155,6 +155,8 @@ class JudgeHandler extends Handler {
|
||||
}
|
||||
|
||||
class JudgeConnectionHandler extends ConnectionHandler {
|
||||
processing: any;
|
||||
|
||||
async message(msg) {
|
||||
if (msg.key === 'next') await next(msg);
|
||||
else if (msg.key === 'end') {
|
||||
|
||||
@@ -15,6 +15,7 @@ function set(key, value) {
|
||||
if (setting.SYSTEM_SETTINGS_BY_KEY[key]) {
|
||||
const s = setting.SYSTEM_SETTINGS_BY_KEY[key];
|
||||
if (s.flag & setting.FLAG_DISABLED) return undefined;
|
||||
if (s.flag & setting.FLAG_SECRET && !value) return undefined;
|
||||
if (s.type === 'boolean') {
|
||||
if (value === 'on') return true;
|
||||
return false;
|
||||
@@ -48,6 +49,8 @@ class SystemMainHandler extends SystemHandler {
|
||||
}
|
||||
|
||||
class SystemCheckConnHandler extends ConnectionHandler {
|
||||
id: any;
|
||||
|
||||
async prepare() {
|
||||
this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
|
||||
await this.check();
|
||||
@@ -61,7 +64,7 @@ class SystemCheckConnHandler extends ConnectionHandler {
|
||||
}
|
||||
|
||||
async cleanup() {
|
||||
check.cancel(this.token);
|
||||
check.cancel(this.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class FileDownloadHandler extends Handler {
|
||||
@param('name', Types.String, true)
|
||||
async get(domainId: string, fileId: ObjectID, secret: string, name: string) {
|
||||
if (name) name = Buffer.from(name, 'base64').toString();
|
||||
this.response.attachment(name || fileId);
|
||||
this.response.attachment(name || fileId.toHexString());
|
||||
this.response.body = await file.getWithSecret(fileId, secret);
|
||||
}
|
||||
}
|
||||
|
||||
+37
-25
@@ -19,8 +19,13 @@ import {
|
||||
NoProblemError, ProblemDataNotFoundError, BadRequestError,
|
||||
SolutionNotFoundError,
|
||||
} from '../error';
|
||||
import { Pdoc, Udoc, Rdoc } from '../interface';
|
||||
|
||||
const parseCategory = (value: string) => flatten(value.split('+').map((e) => e.split(','))).map((e) => e.trim());
|
||||
const parseCategory = (value: string) => {
|
||||
if (!value) return [];
|
||||
console.log(value);
|
||||
return flatten(value.split('+').map((e) => e.split(','))).map((e) => e.trim());
|
||||
};
|
||||
const parsePid = (value: string) => (isSafeInteger(value) ? parseInt(value, 10) : value);
|
||||
|
||||
class ProblemHandler extends Handler {
|
||||
@@ -99,7 +104,7 @@ class ProblemMainHandler extends ProblemHandler {
|
||||
|
||||
class ProblemCategoryHandler extends ProblemHandler {
|
||||
@param('page', Types.UnsignedInt, true)
|
||||
@param('category', Types.String, parseCategory)
|
||||
@param('category', Types.String, null, parseCategory)
|
||||
async get(domainId: string, page = 1, category: string[]) {
|
||||
this.response.template = 'problem_main.html';
|
||||
const q: any = { $and: [] };
|
||||
@@ -136,7 +141,7 @@ class ProblemCategoryHandler extends ProblemHandler {
|
||||
|
||||
class ProblemRandomHandler extends ProblemHandler {
|
||||
@param('category', Types.String, true, null, parseCategory)
|
||||
async get(domainId: string, category: string[]) {
|
||||
async get(domainId: string, category: string[] = []) {
|
||||
const q: any = category.length ? { $and: [] } : {};
|
||||
for (const name of category) {
|
||||
if (name) {
|
||||
@@ -157,31 +162,32 @@ class ProblemRandomHandler extends ProblemHandler {
|
||||
}
|
||||
|
||||
class ProblemDetailHandler extends ProblemHandler {
|
||||
pdoc: Pdoc;
|
||||
|
||||
udoc: Udoc;
|
||||
|
||||
@param('pid', Types.String, null, parsePid)
|
||||
async _prepare(domainId: string, pid: number | string) {
|
||||
this.response.template = 'problem_detail.html';
|
||||
if (pid) {
|
||||
this.pdoc = await problem.get(domainId, pid, this.user._id);
|
||||
if (this.pdoc.hidden && this.pdoc.owner !== this.user._id) {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
}
|
||||
if (this.pdoc) this.udoc = await user.getById(domainId, this.pdoc.owner);
|
||||
this.pdoc = await problem.get(domainId, pid, this.user._id, true);
|
||||
if (this.pdoc.hidden && this.pdoc.owner !== this.user._id) {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
}
|
||||
this.udoc = await user.getById(domainId, this.pdoc.owner);
|
||||
this.response.body = {
|
||||
pdoc: this.pdoc,
|
||||
udoc: this.udoc,
|
||||
title: (this.pdoc || {}).title || '',
|
||||
title: this.pdoc.title,
|
||||
path: [
|
||||
['Hydro', 'homepage'],
|
||||
['problem_main', 'problem_main'],
|
||||
[this.pdoc.title, null, true],
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async get(...args: any) {
|
||||
this.response.body.path = [
|
||||
['Hydro', 'homepage'],
|
||||
['problem_main', 'problem_main'],
|
||||
[this.pdoc.title, null, true],
|
||||
];
|
||||
}
|
||||
// eslint-disable-next-line
|
||||
async get(...args: any[]) { }
|
||||
}
|
||||
|
||||
class ProblemSubmitHandler extends ProblemDetailHandler {
|
||||
@@ -234,6 +240,10 @@ class ProblemPretestHandler extends ProblemDetailHandler {
|
||||
}
|
||||
|
||||
class ProblemPretestConnectionHandler extends ConnectionHandler {
|
||||
pid: string;
|
||||
|
||||
domainId: string;
|
||||
|
||||
@param('pid', Types.String)
|
||||
async prepare(domainId: string, pid: string) {
|
||||
this.pid = pid;
|
||||
@@ -242,7 +252,7 @@ class ProblemPretestConnectionHandler extends ConnectionHandler {
|
||||
}
|
||||
|
||||
async onRecordChange(data) {
|
||||
const rdoc = data.value;
|
||||
const rdoc: Rdoc = data.value;
|
||||
if (
|
||||
rdoc.uid !== this.user._id
|
||||
|| rdoc.pid.toString() !== this.pid
|
||||
@@ -339,23 +349,25 @@ class ProblemDataUploadHandler extends ProblemManageHandler {
|
||||
}
|
||||
|
||||
async get() {
|
||||
let md5;
|
||||
if (this.pdoc.data && typeof this.pdoc.data === 'object') {
|
||||
const f = await file.getMeta(this.pdoc.data);
|
||||
this.md5 = f.md5;
|
||||
md5 = f.md5;
|
||||
}
|
||||
this.response.body.md5 = this.md5;
|
||||
this.response.body.md5 = md5;
|
||||
}
|
||||
|
||||
async post({ domainId }) {
|
||||
let md5;
|
||||
if (!this.request.files.file) throw new BadRequestError();
|
||||
await problem.setTestdata(
|
||||
domainId, this.pdoc.docId, this.request.files.file.path,
|
||||
);
|
||||
if (this.pdoc.data && typeof this.pdoc.data === 'object') {
|
||||
const f = await file.getMeta(this.pdoc.data);
|
||||
this.md5 = f.md5;
|
||||
md5 = f.md5;
|
||||
}
|
||||
this.response.body.md5 = this.md5;
|
||||
this.response.body.md5 = md5;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,7 +380,7 @@ class ProblemDataDownloadHandler extends ProblemDetailHandler {
|
||||
}
|
||||
if (!this.pdoc.data) throw new ProblemDataNotFoundError(pid);
|
||||
else if (typeof this.pdoc.data === 'string') [, this.response.redirect] = this.pdoc.data.split('from:');
|
||||
this.response.redirect = await file.url(this.pdoc.data, `${this.pdoc.title}.zip`);
|
||||
else this.response.redirect = await file.url(this.pdoc.data, `${this.pdoc.title}.zip`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +428,7 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
|
||||
let psdoc = await solution.get(domainId, psid);
|
||||
if (psdoc.owner !== this.user._id) this.checkPerm(PERM.PERM_EDIT_PROBLEM_SOLUTION);
|
||||
else this.checkPerm(PERM.PERM_EDIT_PROBLEM_SOLUTION_SELF);
|
||||
psdoc = await solution.edit(domainId, this.psdoc.docId, content);
|
||||
psdoc = await solution.edit(domainId, psdoc.docId, content);
|
||||
this.back({ psdoc });
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import * as system from '../model/system';
|
||||
import {
|
||||
Route, Handler, Types, param,
|
||||
} from '../service/server';
|
||||
import { Tdoc } from '../interface';
|
||||
|
||||
async function _parseDagJson(domainId, dag) {
|
||||
const parsed = [];
|
||||
@@ -199,6 +200,8 @@ class TrainingCreateHandler extends Handler {
|
||||
}
|
||||
|
||||
class TrainingEditHandler extends Handler {
|
||||
tdoc: Tdoc;
|
||||
|
||||
@param('tid', Types.ObjectID)
|
||||
async prepare(domainId: string, tid: ObjectID) {
|
||||
this.tdoc = await training.get(domainId, tid);
|
||||
|
||||
Reference in new issue
Block a user