File size: 1,734 Bytes
fb14972
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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();