quash: query parameters for just, has, and do, and some general simplification
This commit is contained in:
parent
f2f4e2e704
commit
4720d408f4
14 changed files with 156 additions and 164 deletions
15
www/src/lib/rate-limit.ts
Normal file
15
www/src/lib/rate-limit.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
const requests = new Map<string, number[]>();
|
||||
|
||||
export function isRateLimited(key: string, maxRequests: number, windowMs: number): boolean {
|
||||
const now = Date.now();
|
||||
const timestamps = requests.get(key) ?? [];
|
||||
const recent = timestamps.filter(t => now - t < windowMs);
|
||||
|
||||
if (recent.length >= maxRequests) {
|
||||
return true;
|
||||
}
|
||||
|
||||
recent.push(now);
|
||||
requests.set(key, recent);
|
||||
return false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue