Download server/src/lib/credential.ts from automindy/fokemal: direct link, hf CLI and curl.
- Browser
- Download file 855 Bytes
-
https://huggingface.co/spaces/automindy/fokemal/resolve/main/server/src/lib/credential.ts
- Command line
-
hf download hf://spaces/automindy/fokemal/server/src/lib/credential.ts
-
curl -L -o credential.ts https://huggingface.co/spaces/automindy/fokemal/resolve/main/server/src/lib/credential.ts
855 Bytes
| /** The sentinel the Keys page stores for key-optional platforms and auth-off | |
| * custom endpoints (routes/keys.ts keeps `no-key`), plus the empty string a | |
| * caller can hand a provider when no credential exists. Anything else is a | |
| * real key (#1331). */ | |
| export const NO_KEY_SENTINEL = 'no-key'; | |
| export function isAnonymousCredential(apiKey: string | null | undefined): boolean { | |
| const v = apiKey?.trim() ?? ''; | |
| return v === '' || v === NO_KEY_SENTINEL; | |
| } | |
| /** `Authorization: Bearer <key>` for a real key, nothing for the sentinel: | |
| * upstreams read `Bearer no-key` as an invalid key, so anonymous calls must | |
| * omit the header entirely (#1331). */ | |
| export function bearerAuthHeader(apiKey: string | null | undefined): Record<string, string> { | |
| if (isAnonymousCredential(apiKey)) return {}; | |
| return { Authorization: `Bearer ${apiKey!.trim()}` }; | |
| } | |