diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-08-25 00:44:13 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-08-25 00:44:13 +1000 |
commit | 314a4787ce55a091cb89ef4281d7ba09e8323fa4 (patch) | |
tree | d77142c009e9c6d45390a8fe01c9aee966d7a4cc /src/api/middlewares/RateLimit.ts | |
parent | Merge remote-tracking branch 'upstream/staging' into feat/captchaVerify (diff) | |
parent | case insensitive header for rate limits, fix rate limit default settings (diff) | |
download | server-314a4787ce55a091cb89ef4281d7ba09e8323fa4.tar.xz |
Merge remote-tracking branch 'upstream/staging' into feat/captchaVerify
Diffstat (limited to 'src/api/middlewares/RateLimit.ts')
-rw-r--r-- | src/api/middlewares/RateLimit.ts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/api/middlewares/RateLimit.ts b/src/api/middlewares/RateLimit.ts index 47180b62..dc93dcef 100644 --- a/src/api/middlewares/RateLimit.ts +++ b/src/api/middlewares/RateLimit.ts @@ -1,6 +1,6 @@ -import { Config, getRights, listenEvent, Rights } from "@fosscord/util"; -import { NextFunction, Request, Response, Router } from "express"; import { getIpAdress } from "@fosscord/api"; +import { Config, getRights, listenEvent } from "@fosscord/util"; +import { NextFunction, Request, Response, Router } from "express"; import { API_PREFIX_TRAILING_SLASH } from "./Authentication"; // Docs: https://discord.com/developers/docs/topics/rate-limits @@ -48,7 +48,7 @@ export default function rateLimit(opts: { // exempt user? if so, immediately short circuit if (req.user_id) { const rights = await getRights(req.user_id); - if (rights.has("BYPASS_RATE_LIMITS")) return; + if (rights.has("BYPASS_RATE_LIMITS")) return next(); } const bucket_id = opts.bucket || req.originalUrl.replace(API_PREFIX_TRAILING_SLASH, ""); @@ -121,6 +121,7 @@ export default function rateLimit(opts: { export async function initRateLimits(app: Router) { const { routes, global, ip, error, disabled } = Config.get().limits.rate; if (disabled) return; + console.log("Enabling rate limits..."); await listenEvent(EventRateLimit, (event) => { Cache.set(event.channel_id as string, event.data); event.acknowledge?.(); @@ -163,7 +164,7 @@ export async function initRateLimits(app: Router) { app.use("/auth/register", rateLimit({ onlyIp: true, success: true, ...routes.auth.register })); } -async function hitRoute(opts: { executor_id: string; bucket_id: string; max_hits: number; window: number; }) { +async function hitRoute(opts: { executor_id: string; bucket_id: string; max_hits: number; window: number }) { const id = opts.executor_id + opts.bucket_id; let limit = Cache.get(id); if (!limit) { |