MCPcopy Create free account
hub / github.com/code100x/cms / rateLimit

Function rateLimit

src/lib/utils.ts:187–202  ·  view source on GitHub ↗
(userId: string)

Source from the content-addressed store, hash-verified

185const RATE_LIMIT_INTERVAL = 60000; // Interval in milliseconds (1 minute)
186
187export const rateLimit = (userId: string): boolean => {
188 const now = new Date();
189 const userLimiter = userRateLimits.get(userId) ?? { timestamps: [] };
190
191 userLimiter.timestamps = userLimiter.timestamps.filter(
192 (timestamp) => now.getTime() - timestamp.getTime() < RATE_LIMIT_INTERVAL,
193 );
194
195 if (userLimiter.timestamps.length >= RATE_LIMIT_COUNT) {
196 return false; // Rate limit exceeded
197 }
198
199 userLimiter.timestamps.push(now);
200 userRateLimits.set(userId, userLimiter);
201 return true;
202};
203
204export const getUpdatedUrl = (
205 path: string,

Callers 1

createCommentHandlerFunction · 0.90

Calls 2

getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected