Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/utils/src/ratelimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export function parseRetryAfterHeader(header: string, now: number = Date.now()):
}

/**
* Gets the time that given category is disabled until for rate limiting
* Gets the time that the given category is disabled until for rate limiting.
* In case no category-specific limit is set but a general rate limit across all categories is active,
* that time is returned.
*
* @return the time in ms that the category is disabled until or 0 if there's no active rate limit.
*/
export function disabledUntil(limits: RateLimits, category: string): number {
return limits[category] || limits.all || 0;
Expand All @@ -41,7 +45,8 @@ export function isRateLimited(limits: RateLimits, category: string, now: number

/**
* Update ratelimits from incoming headers.
* Returns true if headers contains a non-empty rate limiting header.
*
* @return the updated RateLimits object.
*/
export function updateRateLimits(
limits: RateLimits,
Expand Down