修复一堆错误

This commit is contained in:
undefined committed 2020-06-20 13:32:53 +08:00
1 parent 2d3cee7753
commit b5e3b81c17
23 files changed
+120 -159

No files matched your search

-41
View File
@@ -274,96 +274,55 @@ class FileTooLongError(ValidationError):
def message(self):
return 'The uploaded file is too long.'
class FileTypeNotAllowedError(ValidationError):
@property
def message(self):
return 'This type of files are not allowed to be uploaded.'
class UnknownFieldError(ForbiddenError):
@property
def message(self):
return 'Unknown field {0}.'
class CsrfTokenError(ForbiddenError):
pass
class InvalidOperationError(ForbiddenError):
pass
class InvalidTokenDigestError(ForbiddenError):
pass
class CurrentPasswordError(ForbiddenError):
@property
def message(self):
return "Current password doesn't match."
class DiscussionCategoryAlreadyExistError(ForbiddenError):
@property
def message(self):
return 'Discussion category {1} already exists.'
class DiscussionCategoryNotFoundError(NotFoundError):
@property
def message(self):
return 'Discussion category {1} not found.'
class DiscussionNodeAlreadyExistError(ForbiddenError):
@property
def message(self):
return 'Discussion node {1} already exists.'
class TrainingRequirementNotSatisfiedError(ForbiddenError):
@property
def message(self):
return 'Training requirement is not satisfied.'
class UsageExceededError(ForbiddenError):
@property
def message(self):
return 'Usage exceeded.'
class InvalidArgumentError(BadRequestError):
@property
def message(self):
return 'Argument {0} is invalid.'
class BatchCopyLimitExceededError(ForbiddenError):
@property
def message(self):
return 'Only {0} problems can be copied in one request, got {1}.'
class UpgradeLockAcquireError(Error):
@property
def message(self):
return 'Failed to acquire the upgrade lock. There may be another ongoing upgrade process, or a previous process is exited unexpectedly.'
class UpgradeLockReleaseError(Error):
@property
def message(self):
return 'Failed to release the upgrade lock. The database is malformed during the upgrade.'
class DatabaseVersionMismatchError(Error):
@property
def message(self):
return 'Database version mismatch, got {0}, expect {1}. You need to invoke database upgrades.'
class SendMailError(UserFacingError):
@property
def message(self):
+20 -19
View File
@@ -31,13 +31,15 @@ class DiscussionHandler extends Handler {
type = discussion.typeDisplay[this.ddoc.parentType];
name = this.ddoc.parentId;
if (drid) {
this.drdoc = await discussion.getReply(domainId, drid, did);
this.drdoc = await discussion.getReply(domainId, drid);
if (!this.drdoc) throw new DiscussionNotFoundError(drid);
if (this.drdoc.parent !== this.ddoc._id) throw new DocumentNotFoundError(drid);
if (!this.drdoc.parentId.equals(this.ddoc._id)) {
throw new DocumentNotFoundError(drid);
}
if (drrid) {
[, this.drrdoc] = await discussion.getTailReply(domainId, drid, drrid);
if (!this.drrdoc) throw new DiscussionNotFoundError(drrid);
if (this.drrdoc.parent !== this.drdoc._id) {
if (!this.drrdoc.parentId.equals(this.drdoc._id)) {
throw new DocumentNotFoundError(drid);
}
}
@@ -196,7 +198,7 @@ class DiscussionDetailHandler extends DiscussionHandler {
async postDeleteReply({ domainId, drid }) {
if (this.drdoc.owner !== this.user._id) this.checkPerm(PERM_DELETE_DISCUSSION_REPLY);
await discussion.deleteReply(domainId, drid);
await discussion.delReply(domainId, drid);
this.back();
}
@@ -210,20 +212,18 @@ class DiscussionDetailHandler extends DiscussionHandler {
async postDeleteTailReply({ domainId, drid, drrid }) {
if (this.drrdoc.owner !== this.user._id) this.checkPerm(PERM_DELETE_DISCUSSION_REPLY);
await discussion.deleteTailReply(domainId, drid, drrid);
await discussion.delTailReply(domainId, drid, drrid);
this.back();
}
async postStar({ domainId, did, star }) {
async postStar({ domainId, did }) {
await discussion.setStar(domainId, did, this.user._id, true);
this.response.body = { star };
this.response.direct = this.request.path;
this.back({ star: true });
}
async postUnstar({ domainId, did, star }) {
async postUnstar({ domainId, did }) {
await discussion.setStar(domainId, did, this.user._id, false);
this.response.body = { star };
this.response.direct = this.request.path;
this.back({ star: false });
}
}
@@ -241,7 +241,6 @@ class DiscussionReplyRawHandler extends DiscussionHandler {
}
}
class DiscussionTailReplyRawHandler extends DiscussionHandler {
async get() {
this.response.type = 'text/markdown';
@@ -263,22 +262,24 @@ class DiscussionEditHandler extends DiscussionHandler {
this.response.body = { ddoc: this.ddoc, path };
}
async post({
domainId, did, title, content, highlight, operation,
async postUpdate({
domainId, did, title, content, highlight,
}) {
if (operation) return;
if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_DISCUSSION);
if (highlight && !this.ddoc.highlight) this.checkPerm(PERM_HIGHLIGHT_DISCUSSION);
await discussion.edit(domainId, did, title, content, highlight);
this.response.body = { did };
this.response.redirect = `/discuss/${did}`;
this.response.redirect = this.url('discussion_detail', { did });
}
async postDelete({ domainId, did }) {
if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM_DELETE_DISCUSSION);
await discussion.delete(domainId, did);
await discussion.del(domainId, did);
this.response.body = { type: this.ddoc.parentType, parent: this.ddoc.parentId };
this.response.redirect = `/discuss/${this.ddoc.parentType}/${this.ddoc.parentId}`;
this.response.redirect = this.url('discussion_node', {
type: discussion.typeDisplay[this.ddoc.parentType],
name: this.ddoc.parentId,
});
}
}
@@ -287,7 +288,7 @@ async function apply() {
Route('discussion_detail', '/discuss/:did', DiscussionDetailHandler);
Route('discussion_edit', '/discuss/:did/edit', DiscussionEditHandler);
Route('discussion_detail', '/discuss/:did/raw', DiscussionDetailRawHandler);
Route('discission_reply_raw', '/discuss/:did/:drid/raw', DiscussionReplyRawHandler);
Route('discussion_reply_raw', '/discuss/:did/:drid/raw', DiscussionReplyRawHandler);
Route('discussion_tail_reply_raw', '/discuss/:did/:drid/:drrid/raw', DiscussionTailReplyRawHandler);
Route('discussion_node', '/discuss/:type/:name', DiscussionNodeHandler);
Route('discussion_create', '/discuss/:type/:name/create', DiscussionCreateHandler);
+2 -1
View File
@@ -14,7 +14,6 @@ class SystemHandler extends Handler {
this.response.body = {
path: [
['Hydro', 'homepage'],
['manage_main', null],
],
};
}
@@ -118,6 +117,8 @@ class SystemSettingHandler extends SystemHandler {
this.response.body.current = {};
this.response.body.settings = setting.SYSTEM_SETTINGS;
for (const s of this.response.body.settings) {
// FIXME no-await-in-loop
// eslint-disable-next-line no-await-in-loop
this.response.body.current[s.key] = await system.get(s.key);
}
}
-1
View File
@@ -1,4 +1,3 @@
const { PERM_JUDGE, PERM_LOGGEDIN } = require('../permission');
const file = require('../model/file');
const user = require('../model/user');
-1
View File
@@ -1,4 +1,3 @@
const fs = require('fs');
const paginate = require('../lib/paginate');
const validator = require('../lib/validator');
const file = require('../model/file');
+2 -1
View File
@@ -61,7 +61,8 @@ class UserRegisterHandler extends Handler {
);
if (await system.get('smtp.user')) {
const m = await this.renderHTML('user_register_mail.html', {
url: `${await system.get('server.url')}/register/${t[0]}`,
path: `register/${t[0]}`,
url_prefix: await system.get('server.url'),
});
await sendMail(mail, 'Sign Up', 'user_register_mail', m);
this.response.template = 'user_register_mail_sent.html';
-8
View File
@@ -59,39 +59,31 @@ ID_RE = re.compile(r'[^\\/\s\u3000]([^\\/\n\r]*[^\\/\s\u3000])?')
def is_id(s):
return bool(ID_RE.fullmatch(s))
def check_category_name(s):
if not is_id(s):
raise error.ValidationError('category_name')
def check_node_name(s):
if not is_id(s):
raise error.ValidationError('node_name')
def is_intro(s):
return isinstance(s, str) and 0 < len(s.strip()) < 500
def check_intro(s):
if not is_intro(s):
raise error.ValidationError('intro')
def is_description(s):
return isinstance(s, str) and len(s) < 65536
def check_description(s):
if not is_description(s):
raise error.ValidationError('description')
def is_lang(i):
return i in constant.language.LANG_TEXTS
def check_lang(i):
if not is_lang(i):
raise error.ValidationError('lang')
+4 -1
View File
@@ -96,7 +96,10 @@ async function load() {
process.stdin.setEncoding('utf8');
process.stdin.on('data', (input) => {
if (input[0] === '@') {
cluster.workers[1].send({ event: 'run', command: input.substr(1, input.length - 1) });
for (const i in cluster.workers) {
cluster.workers[i].send({ event: 'run', command: input.substr(1, input.length - 1) });
break;
}
} else {
executeCommand(input);
}
-1
View File
@@ -186,7 +186,6 @@ const oi = {
rank: (tdocs) => ranked(tdocs, (a, b) => a.score === b.score),
};
const RULES = {
acm, oi,
};
+1 -1
View File
@@ -98,7 +98,7 @@ async function getByEmail(domainId, mail, ignoreMissing = false) {
function setPassword(uid, password) {
const salt = String.random();
return coll.findOneAndUpdate({ _id: uid }, {
$set: { salt, hash: pwhash.hash(password, salt), hashType: 'hydro' },
$set: { salt, hash: pwhash(password, salt), hashType: 'hydro' },
});
}
+8 -8
View File
@@ -194,7 +194,7 @@ class Handler {
}
back(body) {
if (body) this.response.body = body;
this.response.body = body || this.response.body || {};
this.response.redirect = this.request.headers.referer || '/';
}
@@ -225,6 +225,7 @@ class Handler {
if (anchor) return `${res}#${anchor}`;
} catch (e) {
console.error(e.message);
console.log(name, kwargs);
}
return res;
}
@@ -284,16 +285,15 @@ class Handler {
async putResponse() {
if (this.response.disposition) this.ctx.set('Content-Disposition', this.response.disposition);
if (this.response.redirect) {
if (!this.preferJson) {
this.ctx.response.type = 'application/octet-stream';
this.ctx.response.status = 302;
this.ctx.redirect(this.response.redirect);
} else {
if (this.response.redirect && !this.preferJson) {
this.ctx.response.type = 'application/octet-stream';
this.ctx.response.status = 302;
this.ctx.redirect(this.response.redirect);
} else {
if (this.response.body.redirect) {
this.response.body = this.response.body || {};
this.response.body.url = this.response.redirect;
}
} else {
if (this.response.body != null) {
this.ctx.response.body = this.response.body;
this.ctx.response.status = this.response.status || 200;
+1 -3
View File
@@ -1,8 +1,6 @@
const { hasIn } = require("lodash");
const dict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
String.random = function random(digit) {
String.random = function random(digit = 32) {
let str = '';
for (let i = 1; i <= digit; i++) str += dict[Math.floor(Math.random() * 62)];
return str;