()
| 50 | const CLEANUP_INTERVAL = 5 * 60_000; |
| 51 | |
| 52 | function cleanup() { |
| 53 | const now = Date.now(); |
| 54 | if (now - lastCleanup < CLEANUP_INTERVAL) return; |
| 55 | lastCleanup = now; |
| 56 | for (const map of Object.values(rateMaps)) { |
| 57 | for (const [key, bucket] of map) { |
| 58 | if (now >= bucket.resetAt) map.delete(key); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | function getTier(pathname: string): keyof typeof rateMaps { |
| 64 | if (pathname === "/api/summarize") return "ai"; |