aboutsummaryrefslogtreecommitdiff
path: root/174bg/database/volumes/pocketbase/pb_hooks/views/stats.html
blob: b61a1ba9f95cd099a0255afe9ca6efc1a64a8758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{{define "title"}}
    stats
{{end}}

{{define "body"}}
    <p id="app"></p>

    <script>
        window.addEventListener("load", () => {
            setInterval(fetchStats, 100);
        });

        async function fetchStats() {
            let stats = await fetch("/api/stats");
            stats = await stats.json();
            document.getElementById("app").innerHTML = jsonToHtml(stats);
        }

        function jsonToHtml(json) {
            if (json === null || typeof json !== "object") {
                return String(json);
            }

            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}}