auto-claude: subtask-1-3 - Add JSDoc to rateLimiting.ts (RateLimiter class and methods)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
/**
|
||||
* Rate limit entry tracking request count and timestamp
|
||||
*/
|
||||
interface RateLimitEntry {
|
||||
count: number;
|
||||
timestamp: number;
|
||||
@@ -6,6 +9,10 @@ interface RateLimitEntry {
|
||||
const WINDOW_SIZE_MS = 3600000; // 1 hour
|
||||
const MAX_REQUESTS = 5; // Maximum requests per hour
|
||||
|
||||
/**
|
||||
* Rate Limiter for API request throttling
|
||||
* Manages rate limiting based on IP addresses with sliding window
|
||||
*/
|
||||
class RateLimiter {
|
||||
private cache: Map<string, RateLimitEntry>;
|
||||
|
||||
@@ -13,6 +20,9 @@ class RateLimiter {
|
||||
this.cache = new Map();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an IP address is currently rate limited
|
||||
*/
|
||||
isRateLimited(ip: string): boolean {
|
||||
const now = Date.now();
|
||||
const entry = this.cache.get(ip);
|
||||
@@ -35,6 +45,9 @@ class RateLimiter {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remaining attempts for an IP address
|
||||
*/
|
||||
getRemainingAttempts(ip: string): number {
|
||||
const entry = this.cache.get(ip);
|
||||
if (!entry) {
|
||||
@@ -43,6 +56,9 @@ class RateLimiter {
|
||||
return Math.max(0, MAX_REQUESTS - entry.count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time in milliseconds until rate limit resets for an IP
|
||||
*/
|
||||
getTimeToReset(ip: string): number {
|
||||
const entry = this.cache.get(ip);
|
||||
if (!entry) {
|
||||
|
||||
Reference in New Issue
Block a user