* Check platform ban with caching. Returns the ban if active, or null if not banned.
(cacheKey: string, checker: () => Promise<{ banned: boolean; ban?: Ban }>)
| 118 | * Check platform ban with caching. Returns the ban if active, or null if not banned. |
| 119 | */ |
| 120 | async function checkPlatformBan(cacheKey: string, checker: () => Promise<{ banned: boolean; ban?: Ban }>): Promise<Ban | null> { |
| 121 | const now = Date.now(); |
| 122 | const cached = banCache.get(cacheKey); |
| 123 | if (cached && cached.expiresAt > now) { |
| 124 | return cached.banned ? (cached.ban ?? null) : null; |
| 125 | } |
| 126 | |
| 127 | const result = await checker(); |
| 128 | if (banCache.size > 10_000) banCache.clear(); |
| 129 | banCache.set(cacheKey, { |
| 130 | banned: result.banned, |
| 131 | ban: result.ban, |
| 132 | expiresAt: now + BAN_CACHE_TTL_MS, |
| 133 | }); |
| 134 | return result.banned ? (result.ban ?? null) : null; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Send a 403 ban response. |
no test coverage detected