Files
uptimesebi/internal/web/public.go
T
Sebastian UnterschützandClaude Opus 5.5 2b72715a9d feat(statuspage): serve public status pages from api snapshots
Pages render without JavaScript, are matched by verified custom domain
or by slug, and stay available from a stale snapshot for ten minutes if
the API is unreachable. Snapshots contain no targets or error details.

Refs #21, #22

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 08:39:00 +01:00

55 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"io/fs"
"git.zb-server.de/ZB-Server/uptimesebi/internal/agentapi"
)
// PublicAssets decides how a public status page loads its stylesheet:
// linked from the status page server or inlined for a static export.
type PublicAssets struct {
CSSHref string
InlineCSS string
}
// StylesheetText returns the built stylesheet for inlining.
func StylesheetText() (string, error) {
b, err := fs.ReadFile(static, "static/dist/app.css")
return string(b), err
}
// DayBars turns a component's history into bars.
func DayBars(days []agentapi.Day) []Bar {
out := make([]Bar, len(days))
for i, d := range days {
if d.Uptime < 0 {
out[i] = Bar{Status: StatusUnknown, Title: d.Date + " · –"}
continue
}
out[i] = Bar{Status: ratioStatus(d.Uptime), Title: d.Date + " · " + Percent(d.Uptime)}
}
return out
}
// PageStatus maps a page state to the chart statuses used for colors.
func PageStatus(s string) Status {
switch s {
case agentapi.PageOperational:
return StatusUp
case agentapi.PageDegraded:
return StatusDegraded
case agentapi.PageOutage:
return StatusDown
}
return StatusUnknown
}
// UptimeText formats a component's 90-day uptime.
func UptimeText(r float64) string {
if r < 0 {
return "–"
}
return Percent(r)
}