Add digital catalog with shareable flipbook and ktg.montzar.ir deploy files.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
export type RateLimiter = {
|
||||
check: (ip: string) => boolean;
|
||||
};
|
||||
|
||||
export function createRateLimiter(
|
||||
limit: number,
|
||||
windowMs: number,
|
||||
now: () => number = () => Date.now(),
|
||||
): RateLimiter {
|
||||
const hits = new Map<string, number[]>();
|
||||
|
||||
return {
|
||||
check(ip: string) {
|
||||
const t = now();
|
||||
const recent = (hits.get(ip) ?? []).filter((ts) => t - ts < windowMs);
|
||||
if (recent.length >= limit) {
|
||||
hits.set(ip, recent);
|
||||
return false;
|
||||
}
|
||||
recent.push(t);
|
||||
hits.set(ip, recent);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user