mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
eslint: enable extra rules
no-implicit-coercion, no-extra-boolean-cast, no-invalid-this, logical-assignment-operators, no-unmodified-loop-condition
This commit is contained in:
1 parent
5ac9d930b2
commit
7f51df236a
34 files changed
+100
-96
No files matched your search
@@ -546,7 +546,7 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
|
||||
if (size >= system.get('limit.contest_files_size')) {
|
||||
throw new FileLimitExceededError('size');
|
||||
}
|
||||
if (!filename) filename = file.originalFilename || String.random(16);
|
||||
filename ||= file.originalFilename || String.random(16);
|
||||
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
|
||||
await storage.put(`contest/${domainId}/${tid}/${filename}`, file.filepath, this.user._id);
|
||||
const meta = await storage.getMeta(`contest/${domainId}/${tid}/${filename}`);
|
||||
|
||||
@@ -65,8 +65,8 @@ class DiscussionHandler extends Handler {
|
||||
}
|
||||
}
|
||||
if (this.ddoc) {
|
||||
this.ddoc.parentType = this.ddoc.parentType || this.vnode.type;
|
||||
this.ddoc.parentId = this.ddoc.parentId || this.vnode.id;
|
||||
this.ddoc.parentType ||= this.vnode.type;
|
||||
this.ddoc.parentId ||= this.vnode.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,13 +375,11 @@ class HomeMessagesHandler extends Handler {
|
||||
const parsed = {};
|
||||
for (const m of messages) {
|
||||
const target = m.from === this.user._id ? m.to : m.from;
|
||||
if (!parsed[target]) {
|
||||
parsed[target] = {
|
||||
_id: target,
|
||||
udoc: { ...udict[target], avatarUrl: avatar(udict[target].avatar) },
|
||||
messages: [],
|
||||
};
|
||||
}
|
||||
parsed[target] ||= {
|
||||
_id: target,
|
||||
udoc: { ...udict[target], avatarUrl: avatar(udict[target].avatar) },
|
||||
messages: [],
|
||||
};
|
||||
parsed[target].messages.push(m);
|
||||
}
|
||||
await user.setById(this.user._id, { unreadMsg: 0 });
|
||||
|
||||
@@ -115,7 +115,7 @@ export async function postJudge(rdoc: RecordDoc) {
|
||||
}
|
||||
|
||||
export async function end(body: Partial<JudgeResultBody>) {
|
||||
if (body.rid) body.rid = new ObjectID(body.rid);
|
||||
body.rid &&= new ObjectID(body.rid);
|
||||
let rdoc = await record.get(body.rid);
|
||||
if (!rdoc) return;
|
||||
const $set: Partial<RecordDoc> = {};
|
||||
|
||||
@@ -242,7 +242,7 @@ class SystemUserImportHandler extends SystemHandler {
|
||||
try {
|
||||
const data = JSON.parse(extra);
|
||||
if (data.group) {
|
||||
if (!groups[data.group]) groups[data.group] = [];
|
||||
groups[data.group] ||= [];
|
||||
groups[data.group].push(email);
|
||||
}
|
||||
if (data.school) payload.school = data.school;
|
||||
|
||||
@@ -57,7 +57,7 @@ export class FilesHandler extends Handler {
|
||||
if (size >= system.get('limit.user_files_size')) {
|
||||
if (!this.user.hasPriv(PRIV.PRIV_UNLIMITED_QUOTA)) throw new FileLimitExceededError('size');
|
||||
}
|
||||
if (!filename) filename = file.originalFilename || String.random(16);
|
||||
filename ||= file.originalFilename || String.random(16);
|
||||
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
|
||||
if (this.user._files.filter((i) => i.name === filename).length) throw new FileExistsError(filename);
|
||||
await storage.put(`user/${this.user._id}/${filename}`, file.filepath, this.user._id);
|
||||
|
||||
@@ -161,7 +161,7 @@ export class ProblemMainHandler extends Handler {
|
||||
total = result.total;
|
||||
pcountRelation = result.countRelation;
|
||||
if (!result.hits.length) fail = true;
|
||||
if (!query.$and) query.$and = [];
|
||||
query.$and ||= [];
|
||||
query.$and.push({
|
||||
$or: result.hits.map((i) => {
|
||||
const [did, docId] = i.split('/');
|
||||
@@ -723,7 +723,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
async postUploadFile(domainId: string, filename: string, type = 'testdata') {
|
||||
if (this.pdoc.reference) throw new ProblemIsReferencedError('edit files');
|
||||
if (!this.request.files.file) throw new ValidationError('file');
|
||||
if (!filename) filename = this.request.files.file.originalFilename || String.random(16);
|
||||
filename ||= this.request.files.file.originalFilename || String.random(16);
|
||||
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
|
||||
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||
const files = [];
|
||||
|
||||
@@ -15,7 +15,7 @@ async function getStatus() {
|
||||
let desc = '';
|
||||
const online = new Date(stat.updateAt).getTime() > new Date().getTime() - 300000;
|
||||
if (!online) desc = 'Offline';
|
||||
desc = desc || 'Online';
|
||||
desc ||= 'Online';
|
||||
stat.isOnline = online;
|
||||
stat.status = desc;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ export class TrainingFilesHandler extends Handler {
|
||||
if (size >= system.get('limit.contest_files_size')) {
|
||||
throw new FileLimitExceededError('size');
|
||||
}
|
||||
if (!filename) filename = file.originalFilename || String.random(16);
|
||||
filename ||= file.originalFilename || String.random(16);
|
||||
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
|
||||
await storage.put(`training/${domainId}/${tid}/${filename}`, file.filepath, this.user._id);
|
||||
const meta = await storage.getMeta(`training/${domainId}/${tid}/${filename}`);
|
||||
|
||||
@@ -119,7 +119,7 @@ class UserLoginHandler extends Handler {
|
||||
async post(domainId: string, uname: string, password: string, rememberme = false, redirect = '', tfa = '') {
|
||||
if (!system.get('server.login')) throw new BuiltinLoginError();
|
||||
let udoc = await user.getByEmail(domainId, uname);
|
||||
if (!udoc) udoc = await user.getByUname(domainId, uname);
|
||||
udoc ||= await user.getByUname(domainId, uname);
|
||||
if (!udoc) throw new UserNotFoundError(uname);
|
||||
await Promise.all([
|
||||
this.limitRate('user_login', 60, 30, false),
|
||||
@@ -425,7 +425,7 @@ class OauthCallbackHandler extends Handler {
|
||||
}
|
||||
this.checkPriv(PRIV.PRIV_REGISTER_USER);
|
||||
let username = '';
|
||||
r.uname = r.uname || [];
|
||||
r.uname ||= [];
|
||||
r.uname.push(String.random(16));
|
||||
const mailDomain = r.email.split('@')[1];
|
||||
if (await BlackListModel.get(`mail::${mailDomain}`)) throw new BlacklistedError(mailDomain);
|
||||
|
||||
Reference in new issue
Block a user