mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
testdata.convert
This commit is contained in:
1 parent
26f780ddee
commit
0d7d6ea12a
15 files changed
+199
-127
No files matched your search
@@ -141,7 +141,7 @@ class HomeSecurityHandler extends Handler {
|
||||
for (const session of sessions) {
|
||||
if (tokenDigest === md5(session._id)) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await token.delete(session._id, token.TYPE_SESSION);
|
||||
await token.del(session._id, token.TYPE_SESSION);
|
||||
return this.back();
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class HomeSecurityHandler extends Handler {
|
||||
}
|
||||
|
||||
async postDeleteAllTokens() {
|
||||
await token.deleteByUid(this.user._id);
|
||||
await token.delByUid(this.user._id);
|
||||
this.response.redirect = '/login';
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ class UserChangemailWithCodeHandler extends Handler {
|
||||
if (udoc) throw new UserAlreadyExistError(tdoc.mail);
|
||||
await Promise.all([
|
||||
user.setEmail(this.user._id, tdoc.mail),
|
||||
token.delete(code, token.TYPE_CHANGEMAIL),
|
||||
token.del(code, token.TYPE_CHANGEMAIL),
|
||||
]);
|
||||
this.response.redirect = '/home/security';
|
||||
}
|
||||
|
||||
+15
-31
@@ -311,6 +311,18 @@ class HomeworkScoreboardHandler extends HomeworkHandler {
|
||||
}
|
||||
}
|
||||
|
||||
class HomeworkScoreboardDownloadHandler extends HomeworkHandler {
|
||||
async get({ domainId, tid, ext }) {
|
||||
const getContent = {
|
||||
csv: async (rows) => `\uFEFF${rows.map((c) => (c.map((i) => i.value).join(','))).join('\n')}`,
|
||||
html: (rows) => this.renderHTML('contest_scoreboard_download_html.html', { rows }),
|
||||
};
|
||||
if (!getContent[ext]) throw new ValidationError('ext');
|
||||
const [, rows] = await this.getScoreboard(domainId, tid, true, document.TYPE_CONTEST);
|
||||
this.binary(await getContent[ext](rows), `${this.tdoc.title}.${ext}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
contest.isHomeworkExtended = (tdoc) => {
|
||||
const now = new Date().getTime();
|
||||
@@ -456,15 +468,15 @@ async function apply() {
|
||||
Route('homework_create', '/homework/create', HomeworkCreateHandler, PERM_CREATE_HOMEWORK);
|
||||
Route('homework_detail', '/homework/:tid', HomeworkDetailHandler, PERM_VIEW_HOMEWORK);
|
||||
Route('homework_scoreboard', '/homework/:tid/scoreboard', HomeworkScoreboardHandler, PERM_VIEW_HOMEWORK_SCOREBOARD);
|
||||
Route('homework_problem', '/homework/:tid/p/:pid', HomeworkDetailProblemHandler, PERM_VIEW_HOMEWORK);
|
||||
Route('homework_problem_submit', '/homework/:tid/p/:pid/submit', HomeworkDetailProblemSubmitHandler, PERM_SUBMIT_PROBLEM);
|
||||
Route('homework_scoreboard', '/homework/:tid/scoreboard/download/:ext', HomeworkScoreboardDownloadHandler, PERM_VIEW_HOMEWORK_SCOREBOARD);
|
||||
Route('homework_detail_problem', '/homework/:tid/p/:pid', HomeworkDetailProblemHandler, PERM_VIEW_HOMEWORK);
|
||||
Route('homework_detail_problem_submit', '/homework/:tid/p/:pid/submit', HomeworkDetailProblemSubmitHandler, PERM_SUBMIT_PROBLEM);
|
||||
Route('homework_edit', '/homework/:tid/edit', HomeworkEditHandler);
|
||||
}
|
||||
|
||||
global.Hydro.handler.homework = module.exports = apply;
|
||||
|
||||
/*
|
||||
|
||||
@app.route('/homework/{tid:\w{24}}/code', 'homework_code')
|
||||
class HomeworkCodeHandler(base.OperationHandler):
|
||||
@base.limit_rate('homework_code', 3600, 60)
|
||||
@@ -490,32 +502,4 @@ class HomeworkCodeHandler(base.OperationHandler):
|
||||
|
||||
await this.binary(output_buffer.getvalue(), 'application/zip',
|
||||
file_name='{}.zip'.format(tdoc['title']))
|
||||
|
||||
|
||||
@app.route('/homework/{tid}/scoreboard/download/{ext}', 'homework_scoreboard_download')
|
||||
class HomeworkScoreboardDownloadHandler(contest.ContestMixin, base.Handler):
|
||||
def _export_status_as_csv(this, rows):
|
||||
# \r\n for notepad compatibility
|
||||
csv_content = '\r\n'.join([','.join([str(c['value']) for c in row]) for row in rows])
|
||||
data = '\uFEFF' + csv_content
|
||||
return data.encode()
|
||||
|
||||
def _export_status_as_html(this, rows):
|
||||
return this.render_html('contest_scoreboard_download_html.html', rows=rows).encode()
|
||||
|
||||
@base.route_argument
|
||||
@base.require_perm(builtin.PERM_VIEW_HOMEWORK)
|
||||
@base.require_perm(builtin.PERM_VIEW_HOMEWORK_SCOREBOARD)
|
||||
@base.sanitize
|
||||
async def get(this, *, tid: objectid.ObjectId, ext: str):
|
||||
get_status_content = {
|
||||
'csv': this._export_status_as_csv,
|
||||
'html': this._export_status_as_html,
|
||||
}
|
||||
if ext not in get_status_content:
|
||||
raise error.ValidationError('ext')
|
||||
tdoc, rows, udict = await this.get_scoreboard(document.TYPE_HOMEWORK, tid, True)
|
||||
data = get_status_content[ext](rows)
|
||||
file_name = tdoc['title']
|
||||
await this.binary(data, file_name='{}.{}'.format(file_name, ext))
|
||||
*/
|
||||
@@ -9,10 +9,10 @@ const { Route, Handler } = require('../service/server');
|
||||
const coll = db.collection('status');
|
||||
|
||||
class FileDownloadHandler extends Handler {
|
||||
async get({ id, secret, name }) {
|
||||
async get({ docId, secret, name }) {
|
||||
if (name) name = Buffer.from(name, 'base64').toString();
|
||||
this.response.attachment(name || id);
|
||||
this.response.body = await file.get(id, secret);
|
||||
this.response.attachment(name || docId);
|
||||
this.response.body = await file.get(docId, secret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ class MarkdownHandler extends Handler {
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
Route('file_download', '/fs/:id/:secret', FileDownloadHandler);
|
||||
Route('file_download_with_name', '/fs/:id/:name/:secret', FileDownloadHandler);
|
||||
Route('file_download', '/fs/:docId/:secret', FileDownloadHandler);
|
||||
Route('file_download_with_name', '/fs/:docId/:name/:secret', FileDownloadHandler);
|
||||
Route('status', '/status', StatusHandler);
|
||||
Route('status_update', '/status/update', StatusUpdateHandler);
|
||||
Route('switch_language', '/language/:lang', SwitchLanguageHandler);
|
||||
|
||||
@@ -247,8 +247,15 @@ class ProblemSettingsHandler extends ProblemManageHandler {
|
||||
];
|
||||
}
|
||||
|
||||
async post() {
|
||||
// TODO(masnn)
|
||||
async postConfig({ domainId, pid, yaml }) {
|
||||
await problem.edit(domainId, pid, { config: yaml });
|
||||
this.back();
|
||||
}
|
||||
|
||||
async postSetting({
|
||||
domainId, pid, hidden = false, category, tag,
|
||||
}) {
|
||||
await problem.edit(domainId, pid, { hidden, category, tag });
|
||||
this.back();
|
||||
}
|
||||
}
|
||||
@@ -303,7 +310,7 @@ class ProblemDataDownloadHandler extends ProblemDetailHandler {
|
||||
if (this.user._id !== this.pdoc.owner) this.checkPerm([PERM_READ_PROBLEM_DATA, PERM_JUDGE]);
|
||||
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 = file.url(this.pdoc.data, this.pdoc.title);
|
||||
this.response.redirect = await file.url(this.pdoc.data, `${this.pdoc.title}.zip`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class UserRegisterWithCodeHandler extends Handler {
|
||||
await user.create({
|
||||
uid, uname, password, mail, regip: this.request.ip,
|
||||
});
|
||||
await token.delete(code, token.TYPE_REGISTRATION);
|
||||
await token.del(code, token.TYPE_REGISTRATION);
|
||||
this.session.uid = uid;
|
||||
this.response.redirect = '/';
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class UserLostPassWithCodeHandler extends Handler {
|
||||
if (!tdoc) throw new InvalidTokenError(token.TYPE_LOSTPASS, code);
|
||||
if (password !== verifyPassword) throw new VerifyPasswordError();
|
||||
await user.setPassword(tdoc.uid, password);
|
||||
await token.delete(code, token.TYPE_LOSTPASS);
|
||||
await token.del(code, token.TYPE_LOSTPASS);
|
||||
this.response.redirect = '/';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user