(request: Request)
| 44 | } |
| 45 | |
| 46 | function extractAPIKeys(request: Request): string[] { |
| 47 | let auth = request.headers.get("authorization") || request.headers.get("x-api-key") || ""; |
| 48 | if (!auth) return []; |
| 49 | if (!auth.toLowerCase().startsWith("bearer ")) auth = "Bearer " + auth; |
| 50 | return auth.slice(7).split(",").map((t) => t.trim()).filter(Boolean); |
| 51 | } |
| 52 | |
| 53 | async function verifyAPIKey(kv: KVNamespace, apiKey: string): Promise<boolean> { |
| 54 | const val = await kv.get(`ak:${apiKey}`); |