13 lines
354 B
TypeScript
13 lines
354 B
TypeScript
const windowMs = 60 * 60 * 1000;
|
|
const maxHits = 8;
|
|
const buckets = new Map<string, number[]>();
|
|
|
|
export function rateLimitHit(key: string): boolean {
|
|
const now = Date.now();
|
|
const prev = buckets.get(key) ?? [];
|
|
const fresh = prev.filter((t) => now - t < windowMs);
|
|
fresh.push(now);
|
|
buckets.set(key, fresh);
|
|
return fresh.length <= maxHits;
|
|
}
|