(now = Date.now())
| 41 | } |
| 42 | |
| 43 | function cleanupExpiredEntries(now = Date.now()) { |
| 44 | const { windowMs } = getRateLimitConfig(); |
| 45 | const { cooldownMs, activeJobTtlMs } = getRepoProtectionConfig(); |
| 46 | |
| 47 | for (const [ip, entry] of ipRateLimits.entries()) { |
| 48 | if (now - entry.windowStart >= windowMs) { |
| 49 | ipRateLimits.delete(ip); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | for (const [repo, nextAllowedAt] of repoCooldowns.entries()) { |
| 54 | if (now >= nextAllowedAt + cooldownMs) { |
| 55 | repoCooldowns.delete(repo); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | for (const [repo, job] of activeRepoJobs.entries()) { |
| 60 | if (now - job.startedAt >= activeJobTtlMs) { |
| 61 | activeRepoJobs.delete(repo); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | function checkRateLimit(ip, now = Date.now()) { |
| 67 | cleanupExpiredEntries(now); |
no test coverage detected