Download packages/db/src/utils/api-keys.ts from AUXteam/Midday: direct link, hf CLI and curl.
- Browser
- Download file 641 Bytes
-
https://huggingface.co/spaces/AUXteam/Midday/resolve/main/packages/db/src/utils/api-keys.ts
- Command line
-
hf download hf://spaces/AUXteam/Midday/packages/db/src/utils/api-keys.ts
-
curl -L -o api-keys.ts https://huggingface.co/spaces/AUXteam/Midday/resolve/main/packages/db/src/utils/api-keys.ts
641 Bytes
| import { randomBytes } from "node:crypto"; | |
| /** | |
| * Generates a new API key with the format mid_{random_string} | |
| * @returns A new API key string | |
| */ | |
| export function generateApiKey(): string { | |
| // Generate 32 random bytes and convert to hex | |
| const randomString = randomBytes(32).toString("hex"); | |
| return `mid_${randomString}`; | |
| } | |
| /** | |
| * Validates if a string is a valid API key format | |
| * @param key The key to validate | |
| * @returns True if the key starts with 'mid-' and has the correct length | |
| */ | |
| export function isValidApiKeyFormat(key: string): boolean { | |
| return key.startsWith("mid_") && key.length === 68; // mid_ (4) + 64 hex chars | |
| } | |