diff options
Diffstat (limited to '174bg')
| -rw-r--r-- | 174bg/database/volumes/pocketbase/pb_hooks/stats.pb.js | 18 | ||||
| -rw-r--r-- | 174bg/database/volumes/pocketbase/pb_hooks/views/stats.html | 23 |
2 files changed, 29 insertions, 12 deletions
diff --git a/174bg/database/volumes/pocketbase/pb_hooks/stats.pb.js b/174bg/database/volumes/pocketbase/pb_hooks/stats.pb.js index e2b6ab3..3c9617b 100644 --- a/174bg/database/volumes/pocketbase/pb_hooks/stats.pb.js +++ b/174bg/database/volumes/pocketbase/pb_hooks/stats.pb.js @@ -1,6 +1,6 @@ routerAdd("get", "/stats", (e) => { - const heartbeat = $http.send({ - url: "https://db.174bg.net/api/heartbeat", + const stats = $http.send({ + url: "https://db.174bg.net/api/stats", headers: { "content-type": "application/json" } }) @@ -8,7 +8,17 @@ routerAdd("get", "/stats", (e) => { `${__hooks}/views/_layout.html`, `${__hooks}/views/stats.html`, ).render({ - "timeDifference": heartbeat.json.timeDifference, - "withinThreshold": heartbeat.json.withinThreshold, + stats: stats.json, })) +}) + +routerAdd("get", "/api/stats", (e) => { + const heartbeat = $http.send({ + url: "https://db.174bg.net/api/heartbeat", + headers: { "content-type": "application/json" } + }) + + return e.json(200, { + heartbeat: heartbeat.json, + }) })
\ No newline at end of file diff --git a/174bg/database/volumes/pocketbase/pb_hooks/views/stats.html b/174bg/database/volumes/pocketbase/pb_hooks/views/stats.html index b59c1a7..b61a1ba 100644 --- a/174bg/database/volumes/pocketbase/pb_hooks/views/stats.html +++ b/174bg/database/volumes/pocketbase/pb_hooks/views/stats.html @@ -3,8 +3,7 @@ {{end}} {{define "body"}} - <p id="timeDifference">Time Difference: {{.timeDifference}}</p> - <p id="withinThreshold">Within Threshold: {{.withinThreshold}}</p> + <p id="app"></p> <script> window.addEventListener("load", () => { @@ -12,14 +11,22 @@ }); async function fetchStats() { - let heartbeat = await fetch("/api/heartbeat"); - heartbeat = await heartbeat.json(); + let stats = await fetch("/api/stats"); + stats = await stats.json(); + document.getElementById("app").innerHTML = jsonToHtml(stats); + } - const timeDifference = heartbeat.timeDifference; - const withinThreshold = heartbeat.withinThreshold; + function jsonToHtml(json) { + if (json === null || typeof json !== "object") { + return String(json); + } - document.getElementById("timeDifference").textContent = `Time Difference: ${timeDifference}`; - document.getElementById("withinThreshold").textContent = `Within Threshold: ${withinThreshold}`; + let html = "<ul>"; + for (const [key, value] of Object.entries(json)) { + html += `<li>${key}: ${typeof value === "object" && value !== null ? jsonToHtml(value) : String(value)}</li>`; + } + html += "</ul>"; + return html; } </script> {{end}}
\ No newline at end of file |
