File size: 1,256 Bytes
5273cd2
 
 
 
b21e1b7
dc05911
5273cd2
 
 
 
 
dc05911
5273cd2
b21e1b7
 
5273cd2
 
 
b21e1b7
 
dc05911
74adc2f
 
 
 
 
b21e1b7
 
dc05911
74adc2f
 
b21e1b7
dc05911
5273cd2
 
 
b21e1b7
5273cd2
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
import 'dotenv/config';
import express from 'express';
import path from 'path';
import fs from 'fs';
import axios from 'axios';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const app = express();
const PORT = process.env.PORT || 7860;

const REPO_ID = "Gioobc/votolibre-data";
const DATA_URL = `https://huggingface.co/datasets/${REPO_ID}/resolve/main/data/acts.json`;

app.use(express.static('public'));

// Endpoint para obtener las actas desde el Dataset de Hugging Face
app.get('/api/acts', async (req, res) => {
    try {
        const config = {};
        if (process.env.HF_TOKEN) {
            config.headers = { Authorization: `Bearer ${process.env.HF_TOKEN}` };
        }
        const response = await axios.get(DATA_URL, config);
        const data = response.data;
        res.json({ total: data.length, acts: data });
    } catch (e) {
        console.error("Error fetching acts from HF:", e.message);
        // Si no existe el archivo en el Dataset o no hay permisos, devolvemos vacío
        res.json({ total: 0, acts: [] });
    }
});

app.listen(PORT, () => {
    console.log(`🚀 Visor VotoLibre (Dataset Mode) corriendo en puerto ${PORT}`);
});