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}`); });