// Client-Side Engine for Hugging Face Static Space & Node environment document.addEventListener('DOMContentLoaded', async () => { // Lista de 19 espacios incorporada const SPACES = [ { id: "moderador-twisted", name: "moderador twisted", directUrl: "https://asdasdsasda-moderadortwisted.hf.space", spaceUrl: "https://huggingface.co/spaces/asdasdsasda/moderadortwisted", user: "asdasdsasda", repo: "moderadortwisted" }, { id: "waifu-of-brody-bot", name: "Waifu of Brody bot", directUrl: "https://asdasdsasda-waifuofbrodybot.hf.space", spaceUrl: "https://huggingface.co/spaces/asdasdsasda/waifuofbrodybot", user: "asdasdsasda", repo: "waifuofbrodybot" }, { id: "fastbeat-bot", name: "FastBeat Bot", directUrl: "https://brodyloyol-fastbeatbot.hf.space", spaceUrl: "https://huggingface.co/spaces/brodyloyol/fastbeatbot", user: "brodyloyol", repo: "fastbeatbot" }, { id: "waifuofdante-b2", name: "waifuofdante b2", directUrl: "https://brodyloyol-waifuofdanteb2.hf.space", spaceUrl: "https://huggingface.co/spaces/brodyloyol/waifuofdanteb2", user: "brodyloyol", repo: "waifuofdanteb2" }, { id: "waifuof-dante", name: "waifuof dante", directUrl: "https://brodyloyol-waifuofdantebot.hf.space", spaceUrl: "https://huggingface.co/spaces/brodyloyol/waifuofdantebot", user: "brodyloyol", repo: "waifuofdantebot" }, { id: "code-by-dante", name: "code by dante", directUrl: "https://codebybrody-codebydante.hf.space", spaceUrl: "https://huggingface.co/spaces/codebybrody/codebydante", user: "codebybrody", repo: "codebydante" }, { id: "twisted-brody-mangaflow", name: "Twisted Brody MangaFlow", directUrl: "https://codebybrody-twistedbrodymangaflow.hf.space", spaceUrl: "https://huggingface.co/spaces/codebybrody/twistedbrodymangaflow", user: "codebybrody", repo: "twistedbrodymangaflow" }, { id: "brody-file-stream-bot", name: "brody file stream bot", directUrl: "https://codebydante-brodyfilestreambot.hf.space", spaceUrl: "https://huggingface.co/spaces/codebydante/brodyfilestreambot", user: "codebydante", repo: "brodyfilestreambot" }, { id: "twisted-audio", name: "Twisted Audio", directUrl: "https://codebydante-twisted-audio.hf.space", spaceUrl: "https://huggingface.co/spaces/codebydante/twisted-audio", user: "codebydante", repo: "twisted-audio" }, { id: "twisted-brody-mangaflow-bot-telegram", name: "Twisted Brody MangaFlow BOT TELEGRAM", directUrl: "https://codebydante-twistedbrodymangaflowbot.hf.space", spaceUrl: "https://huggingface.co/spaces/codebydante/twistedbrodymangaflowbot", user: "codebydante", repo: "twistedbrodymangaflowbot" }, { id: "twistedstreamingbrody-peliculas-hd-bot", name: "twistedstreamingbrody peliculas HD bot", directUrl: "https://codebydante-twistedstreamingbrody.hf.space", spaceUrl: "https://huggingface.co/spaces/codebydante/twistedstreamingbrody", user: "codebydante", repo: "twistedstreamingbrody" }, { id: "entity-of-brody-bot", name: "Entity of brody bot", directUrl: "https://danteloyola-entitydante.hf.space", spaceUrl: "https://huggingface.co/spaces/danteloyola/entitydante", user: "danteloyola", repo: "entitydante" }, { id: "twistedtraductorbot", name: "@twistedtraductorbot", directUrl: "https://danteloyola-twistedtraductorbot.hf.space", spaceUrl: "https://huggingface.co/spaces/danteloyola/twistedtraductorbot", user: "danteloyola", repo: "twistedtraductorbot" }, { id: "video-album-maker", name: "Video Album Maker", directUrl: "https://danteloyola-videoalbummaker.hf.space", spaceUrl: "https://huggingface.co/spaces/danteloyola/videoalbummaker", user: "danteloyola", repo: "videoalbummaker" }, { id: "bot-unidor", name: "bot unidor", directUrl: "https://danteloyolasalvador-botunidor.hf.space", spaceUrl: "https://huggingface.co/spaces/danteloyolasalvador/botunidor", user: "danteloyolasalvador", repo: "botunidor" }, { id: "user-bot-prime-twisted", name: "user bot prime twisted", directUrl: "https://danteloyolasalvador-userbotfilestream.hf.space", spaceUrl: "https://huggingface.co/spaces/danteloyolasalvador/userbotfilestream", user: "danteloyolasalvador", repo: "userbotfilestream" }, { id: "convertidor-qh", name: "convertidor qh", directUrl: "https://gonzaloloyola-convertidorqh.hf.space", spaceUrl: "https://huggingface.co/spaces/gonzaloloyola/convertidorqh", user: "gonzaloloyola", repo: "convertidorqh" }, { id: "miniaturas-pro-bot", name: "/Miniaturas Pro Bot", directUrl: "https://gonzaloloyola-miniaturasprobot.hf.space", spaceUrl: "https://huggingface.co/spaces/gonzaloloyola/miniaturasprobot", user: "gonzaloloyola", repo: "miniaturasprobot" }, { id: "smartvideosplitterbot", name: "SmartVideoSplitterBot", directUrl: "https://gonzaloloyola-smartvideosplitterbot.hf.space", spaceUrl: "https://huggingface.co/spaces/gonzaloloyola/smartvideosplitterbot", user: "gonzaloloyola", repo: "smartvideosplitterbot" }, { id: "bot-cronologico", name: "Bot Cronológico Pinger", directUrl: "https://codebydante-cronologico.static.hf.space", spaceUrl: "https://huggingface.co/spaces/codebydante/cronologico", user: "codebydante", repo: "cronologico" } ]; // Estado let spacesState = SPACES.map(s => ({ ...s, directStatus: { status: 'PENDING', latencyMs: 0, error: null }, spaceStatus: { status: 'PENDING', latencyMs: 0, error: null }, overallStatus: 'UNKNOWN' })); let cronEnabled = true; let intervalSeconds = 300; let secondsLeft = 300; let isRunning = false; let timerInterval = null; let logCounts = { general: 0, direct: 0, space: 0, alerts: 0 }; // DOM Elements const spacesGrid = document.getElementById('spacesGrid'); const statTotal = document.getElementById('statTotal'); const statOnline = document.getElementById('statOnline'); const statDegraded = document.getElementById('statDegraded'); const statOffline = document.getElementById('statOffline'); const statLatency = document.getElementById('statLatency'); const nextRunTimer = document.getElementById('nextRunTimer'); const searchInput = document.getElementById('searchInput'); const intervalSelect = document.getElementById('intervalSelect'); const btnRunNow = document.getElementById('btnRunNow'); const btnToggleCron = document.getElementById('btnToggleCron'); const cronStatusIcon = document.getElementById('cronStatusIcon'); const cronStatusText = document.getElementById('cronStatusText'); const btnClearConsoles = document.getElementById('btnClearConsoles'); const chkAutoScroll = document.getElementById('chkAutoScroll'); const tabBtns = document.querySelectorAll('.tab-btn'); const consoleBodies = { general: document.getElementById('console-general'), direct: document.getElementById('console-direct'), space: document.getElementById('console-space'), alerts: document.getElementById('console-alerts') }; const badgeGeneral = document.getElementById('badgeGeneral'); const badgeDirect = document.getElementById('badgeDirect'); const badgeSpace = document.getElementById('badgeSpace'); const badgeAlerts = document.getElementById('badgeAlerts'); function logEvent(channel, level, message) { const timeStr = new Date().toLocaleTimeString(); const line = document.createElement('div'); line.className = `log-line level-${level}`; line.innerHTML = ` [${timeStr}] [${channel.toUpperCase()}] ${escapeHtml(message)} `; consoleBodies.general.appendChild(line.cloneNode(true)); logCounts.general++; badgeGeneral.textContent = logCounts.general; if (channel === 'direct') { consoleBodies.direct.appendChild(line.cloneNode(true)); logCounts.direct++; badgeDirect.textContent = logCounts.direct; } else if (channel === 'space') { consoleBodies.space.appendChild(line.cloneNode(true)); logCounts.space++; badgeSpace.textContent = logCounts.space; } else if (channel === 'alerts' || level === 'warn' || level === 'error') { consoleBodies.alerts.appendChild(line.cloneNode(true)); logCounts.alerts++; badgeAlerts.textContent = logCounts.alerts; } if (chkAutoScroll.checked) { Object.values(consoleBodies).forEach(b => b.scrollTop = b.scrollHeight); } } async function pingEndpoint(url) { const start = performance.now(); try { // Intentar fetch no-cors / normal para visitar la página await fetch(url, { mode: 'no-cors', cache: 'no-cache' }); const latencyMs = Math.round(performance.now() - start); return { ok: true, latencyMs, error: null }; } catch (err) { const latencyMs = Math.round(performance.now() - start); return { ok: false, latencyMs, error: err.message }; } } async function diagnoseSpace(index) { const s = spacesState[index]; logEvent('general', 'info', `Iniciando diagnóstico para [${s.name}]...`); // 1. Visit App Directa (.hf.space) logEvent('direct', 'info', `Consultando App Directa: ${s.directUrl}`); const resDirect = await pingEndpoint(s.directUrl); s.directStatus = { status: resDirect.ok ? 'ONLINE' : 'OFFLINE', latencyMs: resDirect.latencyMs, error: resDirect.error }; if (resDirect.ok) { logEvent('direct', 'success', `[App Directa] ${s.name} respondió OK en ${resDirect.latencyMs} ms`); } else { logEvent('direct', 'error', `[App Directa] Fallo en ${s.name}: ${resDirect.error}`); logEvent('alerts', 'warn', `Alerta en App Directa [${s.name}]: ${resDirect.error}`); } // 2. Visit Espacio HF (huggingface.co/spaces/...) logEvent('space', 'info', `Consultando Landing Espacio HF: ${s.spaceUrl}`); const resSpace = await pingEndpoint(s.spaceUrl); s.spaceStatus = { status: resSpace.ok ? 'ONLINE' : 'OFFLINE', latencyMs: resSpace.latencyMs, error: resSpace.error }; if (resSpace.ok) { logEvent('space', 'success', `[Espacio HF] Landing de ${s.name} respondió OK en ${resSpace.latencyMs} ms`); } else { logEvent('space', 'error', `[Espacio HF] Fallo en landing de ${s.name}: ${resSpace.error}`); logEvent('alerts', 'warn', `Alerta en Espacio HF [${s.name}]: ${resSpace.error}`); } // Evaluar estado global if (resDirect.ok && resSpace.ok) { s.overallStatus = 'ONLINE'; logEvent('general', 'success', `Diagnóstico COMPLETADO [${s.name}]: ONLINE (${resDirect.latencyMs}ms / ${resSpace.latencyMs}ms)`); } else if (resDirect.ok || resSpace.ok) { s.overallStatus = 'DEGRADED'; logEvent('general', 'warn', `Diagnóstico PARCIAL [${s.name}]: DEGRADADO`); logEvent('alerts', 'warn', `Espacio [${s.name}] en estado DEGRADADO`); } else { s.overallStatus = 'OFFLINE'; logEvent('general', 'error', `Diagnóstico FALLIDO [${s.name}]: OFFLINE`); logEvent('alerts', 'error', `CRÍTICO: Espacio [${s.name}] está OFFLINE`); } renderGrid(); updateStats(); } async function runCycle() { if (isRunning) return; isRunning = true; secondsLeft = intervalSeconds; logEvent('general', 'info', `=== INICIANDO CICLO DE DIAGNÓSTICO EN VIVO (${spacesState.length} ESPACIOS) ===`); for (let i = 0; i < spacesState.length; i++) { await diagnoseSpace(i); await new Promise(r => setTimeout(r, 200)); } logEvent('general', 'success', `=== CICLO DE DIAGNÓSTICO COMPLETADO CON ÉXITO ===`); isRunning = false; } function renderGrid() { const q = searchInput.value.toLowerCase().trim(); spacesGrid.innerHTML = ''; const filtered = spacesState.filter(s => s.name.toLowerCase().includes(q) || s.user.toLowerCase().includes(q) || s.directUrl.toLowerCase().includes(q) ); filtered.forEach(s => { const card = document.createElement('div'); card.className = 'space-card'; let stClass = 'status-pending'; let stLbl = 'PENDIENTE'; if (s.overallStatus === 'ONLINE') { stClass = 'status-online'; stLbl = 'ONLINE'; } else if (s.overallStatus === 'DEGRADED') { stClass = 'status-degraded'; stLbl = 'DEGRADADO'; } else if (s.overallStatus === 'OFFLINE') { stClass = 'status-offline'; stLbl = 'OFFLINE'; } card.innerHTML = `