diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2024-12-15 16:53:48 +0000 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2024-12-15 16:53:48 +0000 |
| commit | fd0ecb22cf5fb914716418d23545cefb9ecc5aaa (patch) | |
| tree | 7de7ac4cf82b8e6ead4eceb40e44d1ba3d68e5cd /packages/backend/src/misc | |
| parent | merge: Add locales and new navbar entry (!815) (diff) | |
| parent | clarify naming of legacy rate limit methods (diff) | |
| download | sharkey-fd0ecb22cf5fb914716418d23545cefb9ecc5aaa.tar.gz sharkey-fd0ecb22cf5fb914716418d23545cefb9ecc5aaa.tar.bz2 sharkey-fd0ecb22cf5fb914716418d23545cefb9ecc5aaa.zip | |
merge: Fix rate limits under multi-node environments (!809)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/809
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/misc')
| -rw-r--r-- | packages/backend/src/misc/rate-limit-utils.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/backend/src/misc/rate-limit-utils.ts b/packages/backend/src/misc/rate-limit-utils.ts index 9909bb97fa..cc13111390 100644 --- a/packages/backend/src/misc/rate-limit-utils.ts +++ b/packages/backend/src/misc/rate-limit-utils.ts @@ -117,12 +117,27 @@ export interface LimitInfo { fullResetMs: number; } +export const disabledLimitInfo: Readonly<LimitInfo> = Object.freeze({ + blocked: false, + remaining: Number.MAX_SAFE_INTEGER, + resetSec: 0, + resetMs: 0, + fullResetSec: 0, + fullResetMs: 0, +}); + export function isLegacyRateLimit(limit: RateLimit): limit is LegacyRateLimit { return limit.type === undefined; } -export function hasMinLimit(limit: LegacyRateLimit): limit is LegacyRateLimit & { minInterval: number } { - return !!limit.minInterval; +export type MaxLegacyLimit = LegacyRateLimit & { duration: number, max: number }; +export function hasMaxLimit(limit: LegacyRateLimit): limit is MaxLegacyLimit { + return limit.max != null && limit.duration != null; +} + +export type MinLegacyLimit = LegacyRateLimit & { minInterval: number }; +export function hasMinLimit(limit: LegacyRateLimit): limit is MinLegacyLimit { + return limit.minInterval != null; } export function sendRateLimitHeaders(reply: FastifyReply, info: LimitInfo): void { |