this repo has no description madoka.systmes

Update status.js

+14 -19
+14 -19
static/js/status.js
··· 1 1 (function() { 2 - const MONITOR_ID = '12'; 3 - const API_URL = 'https://status.madoka.systems/api/status-page/heartbeat/default'; 2 + const BADGE_URL = 'https://status.madoka.systems/api/badge/12/status'; 4 3 const REFRESH_INTERVAL = 60000; // 1 minute 5 4 6 5 async function fetchStatus() { 7 6 try { 8 - const response = await fetch(API_URL); 9 - if (!response.ok) throw new Error('api request failed'); 7 + const response = await fetch(BADGE_URL); 8 + if (!response.ok) throw new Error('badge request failed'); 10 9 11 - const data = await response.json(); 12 - const heartbeats = data.heartbeatList[MONITOR_ID]; 10 + const svg = await response.text(); 13 11 14 - if (!heartbeats || heartbeats.length === 0) { 12 + // parse status from badge svg text content 13 + if (svg.includes('>Up<') || svg.includes('up</text>')) { 14 + updateIndicator('up'); 15 + } else if (svg.includes('>Down<') || svg.includes('down</text>')) { 16 + updateIndicator('down'); 17 + } else if (svg.includes('>Pending<') || svg.includes('pending</text>')) { 18 + updateIndicator('pending'); 19 + } else if (svg.includes('>Maintenance<') || svg.includes('maintenance</text>')) { 20 + updateIndicator('maintenance'); 21 + } else { 15 22 updateIndicator('unknown'); 16 - return; 17 23 } 18 - 19 - // get most recent heartbeat 20 - const latest = heartbeats[heartbeats.length - 1]; 21 - const status = latest.status; 22 - 23 - // map status codes to css classes 24 - if (status === 1) updateIndicator('up'); 25 - else if (status === 0) updateIndicator('down'); 26 - else if (status === 2) updateIndicator('pending'); 27 - else if (status === 3) updateIndicator('maintenance'); 28 - else updateIndicator('unknown'); 29 24 30 25 } catch (error) { 31 26 console.error('failed to fetch uptime status:', error);