Spaces:
Running
Running
Download lib/cloudflareConfig.ts from 2Btainment/Drip-Creator: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/2Btainment/Drip-Creator/resolve/main/lib/cloudflareConfig.ts
- Command line
-
hf download hf://spaces/2Btainment/Drip-Creator/lib/cloudflareConfig.ts
-
curl -L -o cloudflareConfig.ts https://huggingface.co/spaces/2Btainment/Drip-Creator/resolve/main/lib/cloudflareConfig.ts
1.72 kB
| /* ============================================================ | |
| * Cloudflare-Konfigurations-Validierung | |
| * Verhindert den häufigsten Fehler: Token in der Account-ID. | |
| * ============================================================ */ | |
| /** Echte Cloudflare Account-IDs sind exakt 32 Hex-Zeichen. */ | |
| export const CF_ACCOUNT_ID_RE = /^[a-f0-9]{32}$/i; | |
| /** Neue scannbare Cloudflare-Credential-Formate (Token, KEINE Account-ID). */ | |
| const CF_TOKEN_PREFIXES = /^(cfat_|cfut_|cfk_)/i; | |
| /** | |
| * true, wenn in CF_ACCOUNT_ID versehentlich ein API-Token steht | |
| * (z. B. "cfat_…") statt der 32-stelligen hexadezimalen Account-ID. | |
| */ | |
| export function cfAccountLooksLikeToken(accountId: string): boolean { | |
| return CF_TOKEN_PREFIXES.test(accountId.trim()); | |
| } | |
| /** Konfigurationsstatus für /api/health (keine Werte, nur Diagnose). */ | |
| export function cloudflareStatus(): { configured: boolean; issue: string | null } { | |
| const id = process.env.CF_ACCOUNT_ID?.trim() || ""; | |
| const token = process.env.CF_API_TOKEN?.trim() || ""; | |
| if (!id && !token) return { configured: false, issue: null }; // einfach nicht gesetzt | |
| if (!id) return { configured: false, issue: "CF_ACCOUNT_ID fehlt (32-stellige hex Account-ID aus dem Dashboard)." }; | |
| if (!token) return { configured: false, issue: "CF_API_TOKEN fehlt (API-Token mit Workers-AI-Berechtigung)." }; | |
| if (cfAccountLooksLikeToken(id)) | |
| return { configured: false, issue: "CF_ACCOUNT_ID enthält einen Token (cfat_/cfut_) — dort gehört die 32-stellige hex Account-ID hin." }; | |
| if (!CF_ACCOUNT_ID_RE.test(id)) | |
| return { configured: false, issue: "CF_ACCOUNT_ID hat ein unerwartetes Format (erwartet: 32 Hex-Zeichen)." }; | |
| return { configured: true, issue: null }; | |
| } | |