deploy / deploy (push) Successful in 1m24s
rebuild the public site on the Next.js App Router with static export, per-section SEO pages, metadata, sitemap, robots and a generated OG image add full-screen scroll-snap regions, staged scroll reveals, a hash-free tab navigation with a sliding indicator and region-by-region menu scrolling replace the theme text toggle with animated sun/moon icons restructure the CRM API into config, middleware, models, routes, services and utils layers redesign the CRM shell with a single surface, tab rail, full-width blurred DataTable, record dialogs and mask-based icons update Docker/Nginx publishing, Makefile targets, shared UI polish and docs Co-authored-by: Gitea Actions <-[email protected]>
34 lines
961 B
TypeScript
34 lines
961 B
TypeScript
export interface RateLimitOptions {
|
|
/** Fenêtre glissante, en millisecondes. */
|
|
windowMs: number;
|
|
/** Nombre d'essais autorisés dans la fenêtre. */
|
|
max: number;
|
|
}
|
|
|
|
export interface RateLimiter {
|
|
/** Enregistre une tentative et indique si elle est autorisée. */
|
|
isAllowed: (key: string) => boolean;
|
|
}
|
|
|
|
/**
|
|
* Rate-limit en mémoire, suffisant pour une instance CRM unique. Derrière
|
|
* nginx/Cloudflare, la clé vient de l'IP transmise par `x-forwarded-for`.
|
|
*/
|
|
export const createRateLimiter = ({ windowMs, max }: RateLimitOptions): RateLimiter => {
|
|
const attempts = new Map<string, number[]>();
|
|
|
|
return {
|
|
isAllowed: (key) => {
|
|
const now = Date.now();
|
|
const recent = (attempts.get(key) ?? []).filter((time) => now - time < windowMs);
|
|
if (recent.length >= max) {
|
|
attempts.set(key, recent);
|
|
return false;
|
|
}
|
|
recent.push(now);
|
|
attempts.set(key, recent);
|
|
return true;
|
|
},
|
|
};
|
|
};
|