MCPcopy Create free account
hub / github.com/code100x/daily-code / rateLimit

Function rateLimit

apps/web/lib/auth.ts:52–67  ·  view source on GitHub ↗
(userId: string, rateLimitCount: number, rateLimitInterval: number)

Source from the content-addressed store, hash-verified

50const userRateLimits = new Map<string, RateLimiter>();
51
52export const rateLimit = (userId: string, rateLimitCount: number, rateLimitInterval: number): boolean => {
53 const now = new Date();
54 const userLimiter = userRateLimits.get(userId) ?? { timestamps: [] };
55
56 userLimiter.timestamps = userLimiter.timestamps.filter(
57 (timestamp) => now.getTime() - timestamp.getTime() < rateLimitInterval
58 );
59
60 if (userLimiter.timestamps.length >= rateLimitCount) {
61 return false; // Rate limit exceeded
62 }
63
64 userLimiter.timestamps.push(now);
65 userRateLimits.set(userId, userLimiter);
66 return true;
67};

Callers

nothing calls this directly

Calls 2

getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected