| import fetch from 'node-fetch'; | |
| import * as dotenv from 'dotenv'; | |
| dotenv.config(); | |
| const HF_TOKEN = process.env.HUGGINGFACE_TOKEN; | |
| const SPACE_ID = 'wbes/executive-suites'; | |
| interface Secret { | |
| key: string; | |
| value: string; | |
| } | |
| async function setupSecrets() { | |
| console.log('๐ Setting up Hugging Face secrets...'); | |
| if (!HF_TOKEN) { | |
| throw new Error('HUGGINGFACE_TOKEN not found in environment'); | |
| } | |
| const secrets: Secret[] = [ | |
| { key: 'DATABASE_URL', value: process.env.DATABASE_URL || '' }, | |
| { key: 'NEXTAUTH_SECRET', value: process.env.NEXTAUTH_SECRET || '' }, | |
| { key: 'NEXTAUTH_URL', value: process.env.NEXTAUTH_URL || '' } | |
| ]; | |
| try { | |
| for (const secret of secrets) { | |
| if (!secret.value) { | |
| console.warn(`โ ๏ธ Warning: ${secret.key} is empty`); | |
| continue; | |
| } | |
| const response = await fetch( | |
| `https://huggingface.co/api/spaces/${SPACE_ID}/secrets/${secret.key}`, | |
| { | |
| method: 'PUT', | |
| headers: { | |
| 'Authorization': `Bearer ${HF_TOKEN}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify({ value: secret.value }) | |
| } | |
| ); | |
| if (!response.ok) { | |
| throw new Error(`Failed to set ${secret.key}: ${response.statusText}`); | |
| } | |
| console.log(`โ Set ${secret.key}`); | |
| } | |
| console.log('โ All secrets configured successfully!'); | |
| } catch (error) { | |
| console.error('โ Failed to set secrets:', error); | |
| process.exit(1); | |
| } | |
| } | |
| setupSecrets(); |