This commit is contained in:
2025-08-22 14:11:18 -05:00
commit 3e9ca1a146
88 changed files with 14387 additions and 0 deletions

13
web/lib/rate-limit.ts Normal file
View File

@@ -0,0 +1,13 @@
const hits = new Map<string, { count: number; time: number }>();
export function allow(bucket: string, key: string, limit = 10, windowMs = 60_000) {
const k = `${bucket}:${key}`;
const now = Date.now();
const entry = hits.get(k);
if (!entry || now - entry.time > windowMs) {
hits.set(k, { count: 1, time: now });
return true;
}
if (entry.count >= limit) return false;
entry.count++;
return true;
}