Merge media-webui/media-backend into the general shared component/backend system

Extracts a new backend/authproxy package for the AuthGuard-proxy helper
functions (session cookie handling, input normalization, error
translation) that Bitmagnet/GameStream/media-backend/AutoCode/
CollabTable/PubliSafe/SimpleCollection/SyncServer/UnraidMonitor/
OutdoorGames were each independently reimplementing, and repoints all
of them onto it.

Extends packages/web-ui's Button/Badge with the variants media-webui
needed (outline, icon size, primary badge) and promotes EmptyState/
SectionTitle/Metric/StatusWidget/StatusDialog into the shared library,
then migrates media-webui off its own diverged ui/{button,card,badge,
metric} components and local duplicates of the promoted components
onto @gabriel20xx/web-ui, so media-webui is a proper consumer of the
same design system every other project already uses instead of a
parallel fork.

Also removes the dead `desktop`/MediaDesktop service variant from
media-backend and media-webui (MediaDesktop is an Electron client that
never actually runs this stack).
This commit is contained in:
Gabriel20xx committed 2026-09-03 00:14:01 +02:00
1 parent 9589d07baf
commit 7b5a4e6c2c
49 files changed
+872 -726

No files matched your search

+5 -16
View File
@@ -131,6 +131,7 @@ import (
"golang.org/x/crypto/bcrypt"
sharedauth "repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
"repos.gfranz.ch/Gabriel20xx/shared/backend/authproxy"
)
// User is this service's own /auth/... response shape - UNCHANGED from
@@ -222,25 +223,14 @@ func UserFromContext(ctx context.Context) *User {
// sessionToken reads the AuthGuard session cookie off the incoming request.
// See the top-of-file doc comment's "Session cookie / token model" section.
func (s *Service) sessionToken(r *http.Request) string {
cookie, err := r.Cookie(authclient.DefaultCookieName)
if err != nil || cookie.Value == "" {
return ""
}
return cookie.Value
return authproxy.SessionToken(r)
}
// clearSessionCookies clears both the AuthGuard cookie (as a fallback -
// normally AuthGuard's own Set-Cookie, forwarded via authclient.ForwardCookies,
// already does this) and the pre-migration cookie name.
func (s *Service) clearSessionCookies(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: authclient.DefaultCookieName, Value: "", Path: "/", HttpOnly: true,
Secure: s.secureCookies, SameSite: http.SameSiteLaxMode, MaxAge: -1,
})
http.SetCookie(w, &http.Cookie{
Name: s.cookieName, Value: "", Path: "/", HttpOnly: true,
Secure: s.secureCookies, SameSite: http.SameSiteLaxMode, MaxAge: -1,
})
authproxy.ClearSessionCookies(w, s.cookieName, s.secureCookies)
}
// toUser translates AuthGuard's PublicUser into this service's own User
@@ -1144,9 +1134,8 @@ func (s *Service) SetPassword(ctx context.Context, id int64, password string) er
// non-APIError (a transport failure actually reaching AuthGuard) falls back
// to a generic 500 with fallbackMessage.
func writeAuthGuardError(w http.ResponseWriter, err error, fallbackMessage string) {
var apiErr *authclient.APIError
if errors.As(err, &apiErr) {
writeError(w, apiErr.StatusCode, apiErr.Message)
if statusCode, message, ok := authproxy.APIErrorResponse(err); ok {
writeError(w, statusCode, message)
return
}
writeError(w, http.StatusInternalServerError, fallbackMessage)
-5
View File
@@ -18,7 +18,6 @@ const (
Moderator Service = "moderator"
Kiosk Service = "kiosk"
Servant Service = "servant"
Desktop Service = "desktop"
)
type Config struct {
@@ -137,8 +136,6 @@ func normalizeService(value string) Service {
return Kiosk
case "servant", "mediaservant":
return Servant
case "desktop", "mediadesktop":
return Desktop
default:
return ""
}
@@ -160,8 +157,6 @@ func serviceName(service Service) string {
return "MediaKiosk"
case Servant:
return "MediaServant"
case Desktop:
return "MediaDesktop"
default:
return "MediaCollection"
}
@@ -1060,12 +1060,6 @@ func (s *Server) kioskStatus(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "latestImage": latest, "queueLength": 0})
}
func (s *Server) mountDesktopRoutes(r chi.Router) {
r.Get("/status", func(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "service": "MediaDesktop", "native": true})
})
}
func (s *Server) mountKioskSocket(r chi.Router) {
r.Get("/ws", s.kioskWebsocket)
}
-2
View File
@@ -223,8 +223,6 @@ func (s *Server) mountServiceRoutes(r chi.Router) {
s.mountKioskRoutes(r)
case config.Servant:
s.mountServantRoutes(r)
case config.Desktop:
s.mountDesktopRoutes(r)
}
}