refactored view package

This commit is contained in:
2026-02-09 19:30:47 +11:00
parent 24733098b4
commit d01485d139
47 changed files with 653 additions and 490 deletions

View File

@@ -11,7 +11,7 @@ import (
"git.haelnorr.com/h/oslstats/internal/config"
"git.haelnorr.com/h/oslstats/internal/db"
"git.haelnorr.com/h/oslstats/internal/throw"
"git.haelnorr.com/h/oslstats/internal/view/component/popup"
"git.haelnorr.com/h/oslstats/internal/view/popup"
"github.com/coder/websocket"
"github.com/pkg/errors"
@@ -28,36 +28,24 @@ func NotificationWS(
}
nc, err := setupClient(s, w, r)
if err != nil {
s.LogError(hws.HWSError{
Message: "Failed to get notification client",
Error: err,
Level: hws.ErrorERROR,
StatusCode: http.StatusInternalServerError,
})
logError(s, "Failed to get notification client", errors.Wrap(err, "setupClient"))
return
}
ws, err := websocket.Accept(w, r, &websocket.AcceptOptions{
OriginPatterns: []string{cfg.HWSAuth.TrustedHost},
})
if err != nil {
s.LogError(hws.HWSError{
Message: "Failed to open websocket",
Error: err,
Level: hws.ErrorERROR,
StatusCode: http.StatusInternalServerError,
})
logError(s, "Failed to open websocket", errors.Wrap(err, "websocket.Accept"))
return
}
defer ws.CloseNow()
ctx := ws.CloseRead(r.Context())
err = notifyLoop(ctx, nc, ws)
if err != nil {
s.LogError(hws.HWSError{
Message: "Notification error",
Error: err,
Level: hws.ErrorERROR,
StatusCode: http.StatusInternalServerError,
})
logError(s, "Notification error", errors.Wrap(err, "notifyLoop"))
}
err = ws.CloseNow()
if err != nil {
logError(s, "Error closing websocket", errors.Wrap(err, "ws.CloseNow"))
}
},
)