TrustWin-Landing/src/lib/rate-limit.ts
2026-03-22 03:22:04 +03:00

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;
}