tangled
alpha
login
or
join now
madoka.systems
/
labyrinth
0
fork
atom
this repo has no description
madoka.systmes
0
fork
atom
overview
issues
pulls
pipelines
Update status.js
madoka.systems
1 month ago
085dd118
05051a89
1/1
deploy.yaml
success
53s
+14
-19
1 changed file
expand all
collapse all
unified
split
static
js
status.js
+14
-19
static/js/status.js
···
1
1
(function() {
2
2
-
const MONITOR_ID = '12';
3
3
-
const API_URL = 'https://status.madoka.systems/api/status-page/heartbeat/default';
2
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
8
-
const response = await fetch(API_URL);
9
9
-
if (!response.ok) throw new Error('api request failed');
7
7
+
const response = await fetch(BADGE_URL);
8
8
+
if (!response.ok) throw new Error('badge request failed');
10
9
11
11
-
const data = await response.json();
12
12
-
const heartbeats = data.heartbeatList[MONITOR_ID];
10
10
+
const svg = await response.text();
13
11
14
14
-
if (!heartbeats || heartbeats.length === 0) {
12
12
+
// parse status from badge svg text content
13
13
+
if (svg.includes('>Up<') || svg.includes('up</text>')) {
14
14
+
updateIndicator('up');
15
15
+
} else if (svg.includes('>Down<') || svg.includes('down</text>')) {
16
16
+
updateIndicator('down');
17
17
+
} else if (svg.includes('>Pending<') || svg.includes('pending</text>')) {
18
18
+
updateIndicator('pending');
19
19
+
} else if (svg.includes('>Maintenance<') || svg.includes('maintenance</text>')) {
20
20
+
updateIndicator('maintenance');
21
21
+
} else {
15
22
updateIndicator('unknown');
16
16
-
return;
17
23
}
18
18
-
19
19
-
// get most recent heartbeat
20
20
-
const latest = heartbeats[heartbeats.length - 1];
21
21
-
const status = latest.status;
22
22
-
23
23
-
// map status codes to css classes
24
24
-
if (status === 1) updateIndicator('up');
25
25
-
else if (status === 0) updateIndicator('down');
26
26
-
else if (status === 2) updateIndicator('pending');
27
27
-
else if (status === 3) updateIndicator('maintenance');
28
28
-
else updateIndicator('unknown');
29
24
30
25
} catch (error) {
31
26
console.error('failed to fetch uptime status:', error);