MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / checkRateLimit

Function checkRateLimit

apps/api/src/controllers/tools.controller.ts:98–117  ·  view source on GitHub ↗
(
  key: string,
  windowMs: number,
  max: number,
)

Source from the content-addressed store, hash-verified

96const IP_LOOKUP_MAX = 20;
97
98function checkRateLimit(
99 key: string,
100 windowMs: number,
101 max: number,
102): boolean {
103 const now = Date.now();
104 const record = rateLimitMap.get(key);
105
106 if (!record || now > record.resetAt) {
107 rateLimitMap.set(key, { count: 1, resetAt: now + windowMs });
108 return true;
109 }
110
111 if (record.count >= max) {
112 return false;
113 }
114
115 record.count++;
116 return true;
117}
118
119function detectCDN(headers: Headers): string | null {
120 const server = headers.get('server')?.toLowerCase() || '';

Callers 2

siteCheckerFunction · 0.85
ipLookupFunction · 0.85

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected