Add ESLint (#941)
* Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint
This commit is contained in:
@@ -54,11 +54,12 @@ export const API_PREFIX = /^\/api(\/v\d+)?/;
|
||||
export const API_PREFIX_TRAILING_SLASH = /^\/api(\/v\d+)?\//;
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace Express {
|
||||
interface Request {
|
||||
user_id: string;
|
||||
user_bot: boolean;
|
||||
token: string;
|
||||
token: { id: string; iat: number };
|
||||
rights: Rights;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +88,7 @@ export async function Authentication(
|
||||
try {
|
||||
const { jwtSecret } = Config.get().security;
|
||||
|
||||
const { decoded, user }: any = await checkToken(
|
||||
const { decoded, user } = await checkToken(
|
||||
req.headers.authorization,
|
||||
jwtSecret,
|
||||
);
|
||||
@@ -97,7 +98,8 @@ export async function Authentication(
|
||||
req.user_bot = user.bot;
|
||||
req.rights = new Rights(Number(user.rights));
|
||||
return next();
|
||||
} catch (error: any) {
|
||||
return next(new HTTPError(error?.toString(), 400));
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return next(new HTTPError(error!.toString(), 400));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ type RateLimit = {
|
||||
expires_at: Date;
|
||||
};
|
||||
|
||||
let Cache = new Map<string, RateLimit>();
|
||||
const Cache = new Map<string, RateLimit>();
|
||||
const EventRateLimit = "RATELIMIT";
|
||||
|
||||
export default function rateLimit(opts: {
|
||||
@@ -57,12 +57,8 @@ export default function rateLimit(opts: {
|
||||
error?: boolean;
|
||||
success?: boolean;
|
||||
onlyIp?: boolean;
|
||||
}): any {
|
||||
return async (
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction,
|
||||
): Promise<any> => {
|
||||
}) {
|
||||
return async (req: Request, res: Response, next: NextFunction) => {
|
||||
// exempt user? if so, immediately short circuit
|
||||
if (req.user_id) {
|
||||
const rights = await getRights(req.user_id);
|
||||
@@ -85,7 +81,7 @@ export default function rateLimit(opts: {
|
||||
)
|
||||
max_hits = opts.MODIFY;
|
||||
|
||||
let offender = Cache.get(executor_id + bucket_id);
|
||||
const offender = Cache.get(executor_id + bucket_id);
|
||||
|
||||
if (offender) {
|
||||
let reset = offender.expires_at.getTime();
|
||||
|
||||
Reference in New Issue
Block a user