From 7b5a4e6c2c776682f8d479cd3e39bf09c96ad426 Mon Sep 17 00:00:00 2001 From: Gabriel20xx Date: Thu, 3 Sep 2026 00:14:01 +0200 Subject: [PATCH] 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). --- backend/authproxy/authproxy.go | 135 ++++++++++++ backend/authproxy/authproxy_test.go | 150 +++++++++++++ media-backend/README.md | 2 +- media-backend/internal/auth/auth.go | 21 +- media-backend/internal/config/config.go | 5 - .../internal/server/admin_storage.go | 6 - media-backend/internal/server/server.go | 2 - media-webui/package.json | 1 - media-webui/project-icons.json | 3 +- media-webui/scripts/build-all.mjs | 1 - media-webui/src/lib/app-config.ts | 23 -- .../src/lib/components/AnalyzerHistory.svelte | 12 +- .../lib/components/AnalyzerLiveStatus.svelte | 12 +- .../AnalyzerPipelineBreakdown.svelte | 3 +- .../src/lib/components/EmptyState.svelte | 14 -- .../lib/components/PipelineFlowDiagram.svelte | 14 +- .../src/lib/components/SectionTitle.svelte | 10 - .../src/lib/components/SettingsDialog.svelte | 125 +++++------ .../src/lib/components/StatusDialog.svelte | 102 --------- .../src/lib/components/StatusWidget.svelte | 97 --------- .../src/lib/components/WorkspacePage.svelte | 3 - .../src/lib/components/ui/badge.svelte | 32 --- .../src/lib/components/ui/button.svelte | 43 ---- media-webui/src/lib/components/ui/card.svelte | 14 -- .../src/lib/components/ui/metric.svelte | 32 --- .../src/lib/features/AnalyzerWorkspace.svelte | 26 +-- .../src/lib/features/ConfigWorkspace.svelte | 25 +-- .../src/lib/features/DesktopWorkspace.svelte | 99 --------- .../src/lib/features/FeedWorkspace.svelte | 7 +- .../src/lib/features/KioskWorkspace.svelte | 10 +- .../src/lib/features/MediaTypePipeline.svelte | 8 +- .../lib/features/ModeratorWorkspace.svelte | 22 +- .../src/lib/features/ServantWorkspace.svelte | 12 +- .../src/lib/features/TagsWorkspace.svelte | 7 +- .../src/lib/features/ToolsWorkspace.svelte | 14 +- media-webui/src/lib/features/VideoPage.svelte | 16 +- .../src/lib/features/ViewerWorkspace.svelte | 11 +- media-webui/src/lib/status.ts | 17 -- media-webui/src/lib/types.ts | 2 +- .../web-ui/src/lib/components/Badge.svelte | 10 +- .../web-ui/src/lib/components/Button.svelte | 11 +- .../src/lib/components/EmptyState.svelte | 13 ++ .../web-ui/src/lib/components/Metric.svelte | 21 ++ .../src/lib/components/SectionTitle.svelte | 8 + .../src/lib/components/StatusDialog.svelte | 71 +++++++ .../src/lib/components/StatusWidget.svelte | 103 +++++++++ packages/web-ui/src/lib/index.ts | 8 + packages/web-ui/src/lib/styles.css | 197 ++++++++++++++++++ packages/web-ui/src/lib/types.ts | 18 ++ 49 files changed, 872 insertions(+), 726 deletions(-) create mode 100644 backend/authproxy/authproxy.go create mode 100644 backend/authproxy/authproxy_test.go delete mode 100644 media-webui/src/lib/components/EmptyState.svelte delete mode 100644 media-webui/src/lib/components/SectionTitle.svelte delete mode 100644 media-webui/src/lib/components/StatusDialog.svelte delete mode 100644 media-webui/src/lib/components/StatusWidget.svelte delete mode 100644 media-webui/src/lib/components/ui/badge.svelte delete mode 100644 media-webui/src/lib/components/ui/button.svelte delete mode 100644 media-webui/src/lib/components/ui/card.svelte delete mode 100644 media-webui/src/lib/components/ui/metric.svelte delete mode 100644 media-webui/src/lib/features/DesktopWorkspace.svelte delete mode 100644 media-webui/src/lib/status.ts create mode 100644 packages/web-ui/src/lib/components/EmptyState.svelte create mode 100644 packages/web-ui/src/lib/components/Metric.svelte create mode 100644 packages/web-ui/src/lib/components/SectionTitle.svelte create mode 100644 packages/web-ui/src/lib/components/StatusDialog.svelte create mode 100644 packages/web-ui/src/lib/components/StatusWidget.svelte diff --git a/backend/authproxy/authproxy.go b/backend/authproxy/authproxy.go new file mode 100644 index 0000000..a1bbdba --- /dev/null +++ b/backend/authproxy/authproxy.go @@ -0,0 +1,135 @@ +// Package authproxy holds small helpers shared by every Go service in this +// workspace that proxies its own /auth/... (or /api/auth/...) HTTP surface +// to a centralized AuthGuard instance via shared/backend/authclient, instead +// of embedding its own local user table. +// +// Three services independently reimplemented the same handful of pieces +// below before this package existed (Forks/Bitmagnet/backend/internal/auth/service.go, +// Original/GameStream/backend/cmd/gamestreamd/auth.go, +// Central/shared/media-backend/internal/auth/auth.go — read any one of +// their top-of-file doc comments for the fuller AuthGuard-migration +// rationale: session cookie forwarding, the local one-time setup-claim +// flag, "auth disabled" mode, etc.). Those pieces stay project-specific +// (they depend on each project's own storage/framework/response shape) — +// only the pieces below were duplicated near-verbatim everywhere: +// +// - SessionToken / ClearSessionCookies: reading and clearing AuthGuard's +// own session cookie is identical logic in every caller, since none of +// them mint a session token of their own anymore. +// - NormalizeUsername / NormalizeEmail / ValidPassword: the same +// trim+shape checks, just with different max/min lengths and (kept +// deliberately un-touched by this package) different caller-owned +// error messages — see each function's doc comment for why this +// package returns a plain (value, bool) rather than an error. +// - APIErrorResponse: unwrapping an authclient.APIError into the +// (status code, message) pair every caller's own writeError-equivalent +// forwards close to verbatim. +package authproxy + +import ( + "errors" + "net/http" + "strings" + "unicode/utf8" + + authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient" +) + +// CookieReader is the minimal interface SessionToken needs from an incoming +// request — just *http.Request.Cookie's signature, not the whole request. +// *http.Request satisfies this trivially; a caller (like Bitmagnet's own +// internal/auth.HTTPContext) that deliberately abstracts its request behind +// a narrower interface of its own, e.g. for testability, can pass that +// directly instead of needing a concrete *http.Request. +type CookieReader interface { + Cookie(name string) (*http.Cookie, error) +} + +// SessionToken reads AuthGuard's own session cookie +// (authclient.DefaultCookieName) off an incoming request, returning "" if +// it is absent or empty. Every AuthGuard-proxying service in this workspace +// mints no session token of its own — AuthGuard's cookie *is* the session — +// so this same read is duplicated in every one of them. +func SessionToken(r CookieReader) string { + cookie, err := r.Cookie(authclient.DefaultCookieName) + if err != nil || cookie.Value == "" { + return "" + } + return cookie.Value +} + +// ClearSessionCookies clears AuthGuard's own session cookie plus one +// legacy, pre-migration cookie name a caller's browser might still be +// holding (each project's own cookie name from before it adopted +// AuthGuard — e.g. "gamestream_session", "bitmagnet_session", +// "mediacollection_session"; pass "" if a given caller has none). Normally +// AuthGuard's own Set-Cookie header, forwarded via authclient.ForwardCookies, +// already clears its cookie on logout — every project's own Logout handler +// also calls this explicitly as a fallback and to clear the legacy cookie, +// which AuthGuard has no way to know about. +func ClearSessionCookies(w http.ResponseWriter, legacyCookieName string, secure bool) { + http.SetCookie(w, &http.Cookie{ + Name: authclient.DefaultCookieName, Value: "", Path: "/", HttpOnly: true, + Secure: secure, SameSite: http.SameSiteLaxMode, MaxAge: -1, + }) + if legacyCookieName != "" && legacyCookieName != authclient.DefaultCookieName { + http.SetCookie(w, &http.Cookie{ + Name: legacyCookieName, Value: "", Path: "/", HttpOnly: true, + Secure: secure, SameSite: http.SameSiteLaxMode, MaxAge: -1, + }) + } +} + +// NormalizeUsername reports whether value, once trimmed, is non-empty and +// no longer than maxLen runes, and returns the trimmed value either way. +// +// This returns (value, bool) rather than (value, error) deliberately: every +// existing caller already owns its own error value/message for this +// failure (e.g. "username is required", "invalid authentication input: +// username must be between 1 and 64 characters") as part of its public API +// response shape, and unifying those messages was not part of what made +// this duplicated — only the trim+shape check was. A caller with "empty +// means leave this field unchanged" update semantics (a partial-update +// endpoint) should special-case an empty value itself before calling this, +// since this function always reports false for one. +func NormalizeUsername(value string, maxLen int) (normalized string, ok bool) { + normalized = strings.TrimSpace(value) + return normalized, normalized != "" && utf8.RuneCountInString(normalized) <= maxLen +} + +// NormalizeEmail reports whether value, once lowercased and trimmed, looks +// like a valid email address (exactly one "@", a non-empty local part, and +// a domain part containing at least one ".") and is no longer than maxLen +// runes, and returns the normalized value either way. Same (value, bool) +// shape and rationale as NormalizeUsername. +func NormalizeEmail(value string, maxLen int) (normalized string, ok bool) { + normalized = strings.ToLower(strings.TrimSpace(value)) + if normalized == "" || utf8.RuneCountInString(normalized) > maxLen || strings.Count(normalized, "@") != 1 { + return normalized, false + } + local, domain, _ := strings.Cut(normalized, "@") + if local == "" || domain == "" || !strings.Contains(domain, ".") { + return normalized, false + } + return normalized, true +} + +// ValidPassword reports whether password is at least minLen runes long. +func ValidPassword(password string, minLen int) bool { + return utf8.RuneCountInString(password) >= minLen +} + +// APIErrorResponse extracts the HTTP status code and message an +// authclient.APIError carries, for a caller's own writeError-equivalent to +// forward. ok is false when err is not an *authclient.APIError (a +// transport failure actually reaching AuthGuard, as opposed to AuthGuard +// giving a real answer the caller didn't like) — callers should fall back +// to a generic 500 with their own message in that case, matching every +// existing writeAuthGuardError implementation's behavior. +func APIErrorResponse(err error) (statusCode int, message string, ok bool) { + var apiErr *authclient.APIError + if errors.As(err, &apiErr) { + return apiErr.StatusCode, apiErr.Message, true + } + return 0, "", false +} diff --git a/backend/authproxy/authproxy_test.go b/backend/authproxy/authproxy_test.go new file mode 100644 index 0000000..1354b66 --- /dev/null +++ b/backend/authproxy/authproxy_test.go @@ -0,0 +1,150 @@ +package authproxy + +import ( + "errors" + "net/http" + "net/http/httptest" + "testing" + + authclient "repos.gfranz.ch/Gabriel20xx/shared/backend/authclient" +) + +func TestSessionToken(t *testing.T) { + cases := []struct { + name string + cookie *http.Cookie + want string + }{ + {name: "no cookie", want: ""}, + {name: "present", cookie: &http.Cookie{Name: authclient.DefaultCookieName, Value: "tok123"}, want: "tok123"}, + {name: "empty value", cookie: &http.Cookie{Name: authclient.DefaultCookieName, Value: ""}, want: ""}, + {name: "wrong cookie name", cookie: &http.Cookie{Name: "other", Value: "tok123"}, want: ""}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + r := httptest.NewRequest(http.MethodGet, "/", nil) + if tc.cookie != nil { + r.AddCookie(tc.cookie) + } + if got := SessionToken(r); got != tc.want { + t.Fatalf("SessionToken() = %q, want %q", got, tc.want) + } + }) + } +} + +func TestClearSessionCookies(t *testing.T) { + w := httptest.NewRecorder() + ClearSessionCookies(w, "legacy_session", true) + + resp := w.Result() + cookies := resp.Cookies() + if len(cookies) != 2 { + t.Fatalf("got %d Set-Cookie headers, want 2: %+v", len(cookies), cookies) + } + byName := map[string]*http.Cookie{} + for _, c := range cookies { + byName[c.Name] = c + } + for _, name := range []string{authclient.DefaultCookieName, "legacy_session"} { + c, ok := byName[name] + if !ok { + t.Fatalf("missing Set-Cookie for %q", name) + } + if c.Value != "" || c.MaxAge != -1 || !c.HttpOnly || !c.Secure { + t.Fatalf("cookie %q not cleared correctly: %+v", name, c) + } + } +} + +func TestClearSessionCookiesNoLegacyName(t *testing.T) { + w := httptest.NewRecorder() + ClearSessionCookies(w, "", false) + + if got := len(w.Result().Cookies()); got != 1 { + t.Fatalf("got %d Set-Cookie headers, want 1 (no legacy name given)", got) + } +} + +func TestClearSessionCookiesLegacyEqualsDefault(t *testing.T) { + w := httptest.NewRecorder() + ClearSessionCookies(w, authclient.DefaultCookieName, false) + + if got := len(w.Result().Cookies()); got != 1 { + t.Fatalf("got %d Set-Cookie headers, want 1 (legacy name equals AuthGuard's own)", got) + } +} + +func TestNormalizeUsername(t *testing.T) { + cases := []struct { + name string + input string + want string + ok bool + }{ + {name: "valid", input: " gabriel ", want: "gabriel", ok: true}, + {name: "empty", input: " ", want: "", ok: false}, + {name: "too long", input: string(make([]byte, 65)), want: string(make([]byte, 65)), ok: false}, + {name: "exactly max", input: "1234567890", want: "1234567890", ok: true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got, ok := NormalizeUsername(tc.input, 10) + if got != tc.want || ok != tc.ok { + t.Fatalf("NormalizeUsername(%q, 10) = (%q, %v), want (%q, %v)", tc.input, got, ok, tc.want, tc.ok) + } + }) + } +} + +func TestNormalizeEmail(t *testing.T) { + cases := []struct { + name string + input string + want string + ok bool + }{ + {name: "valid", input: " Gabriel@Example.COM ", want: "gabriel@example.com", ok: true}, + {name: "empty", input: "", want: "", ok: false}, + {name: "no at", input: "gabriel.example.com", want: "gabriel.example.com", ok: false}, + {name: "two ats", input: "a@b@c.com", want: "a@b@c.com", ok: false}, + {name: "empty local part", input: "@example.com", want: "@example.com", ok: false}, + {name: "empty domain", input: "gabriel@", want: "gabriel@", ok: false}, + {name: "domain without dot", input: "gabriel@localhost", want: "gabriel@localhost", ok: false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got, ok := NormalizeEmail(tc.input, 254) + if got != tc.want || ok != tc.ok { + t.Fatalf("NormalizeEmail(%q, 254) = (%q, %v), want (%q, %v)", tc.input, got, ok, tc.want, tc.ok) + } + }) + } +} + +func TestValidPassword(t *testing.T) { + if ValidPassword("short", 8) { + t.Fatal("expected 5-char password to fail an 8-char minimum") + } + if !ValidPassword("longenough", 8) { + t.Fatal("expected 10-char password to pass an 8-char minimum") + } +} + +func TestAPIErrorResponse(t *testing.T) { + t.Run("api error", func(t *testing.T) { + apiErr := &authclient.APIError{StatusCode: http.StatusConflict, Message: "already exists"} + status, message, ok := APIErrorResponse(apiErr) + if !ok || status != http.StatusConflict || message != "already exists" { + t.Fatalf("APIErrorResponse() = (%d, %q, %v), want (409, %q, true)", status, message, ok, "already exists") + } + }) + + t.Run("non-api error", func(t *testing.T) { + _, _, ok := APIErrorResponse(errors.New("transport failure")) + if ok { + t.Fatal("expected ok=false for a non-APIError") + } + }) +} diff --git a/media-backend/README.md b/media-backend/README.md index 3c3a21a..cf59241 100644 --- a/media-backend/README.md +++ b/media-backend/README.md @@ -1,6 +1,6 @@ # MediaCollection Go backend -The backend is one Go module. Set `MEDIA_SERVICE` to `viewer`, `tools`, `analyzer`, `config`, `moderator`, `kiosk`, `servant`, or `desktop` to select the route set while keeping the same auth, database, migration, file-safety, and worker implementation. +The backend is one Go module. Set `MEDIA_SERVICE` to `viewer`, `tools`, `analyzer`, `config`, `moderator`, `kiosk`, or `servant` to select the route set while keeping the same auth, database, migration, file-safety, and worker implementation. From this directory: diff --git a/media-backend/internal/auth/auth.go b/media-backend/internal/auth/auth.go index ffca852..da52081 100644 --- a/media-backend/internal/auth/auth.go +++ b/media-backend/internal/auth/auth.go @@ -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) diff --git a/media-backend/internal/config/config.go b/media-backend/internal/config/config.go index 2f7a183..06a23ef 100644 --- a/media-backend/internal/config/config.go +++ b/media-backend/internal/config/config.go @@ -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" } diff --git a/media-backend/internal/server/admin_storage.go b/media-backend/internal/server/admin_storage.go index db08f38..7370fbe 100644 --- a/media-backend/internal/server/admin_storage.go +++ b/media-backend/internal/server/admin_storage.go @@ -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) } diff --git a/media-backend/internal/server/server.go b/media-backend/internal/server/server.go index 96d127f..e0b7c9f 100644 --- a/media-backend/internal/server/server.go +++ b/media-backend/internal/server/server.go @@ -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) } } diff --git a/media-webui/package.json b/media-webui/package.json index 961f011..10711cf 100644 --- a/media-webui/package.json +++ b/media-webui/package.json @@ -14,7 +14,6 @@ "build:moderator": "node scripts/build-all.mjs moderator", "build:kiosk": "node scripts/build-all.mjs kiosk", "build:servant": "node scripts/build-all.mjs servant", - "build:desktop": "node scripts/build-all.mjs desktop", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "lint": "eslint .", "format": "prettier --write .", diff --git a/media-webui/project-icons.json b/media-webui/project-icons.json index efa1845..dbab482 100644 --- a/media-webui/project-icons.json +++ b/media-webui/project-icons.json @@ -5,6 +5,5 @@ "config": { "name": "MediaConfig", "icon": "settings-2" }, "moderator": { "name": "MediaModerator", "icon": "shield-check" }, "kiosk": { "name": "MediaKiosk", "icon": "image" }, - "servant": { "name": "MediaServant", "icon": "server" }, - "desktop": { "name": "MediaViewer Desktop", "icon": "monitor-play" } + "servant": { "name": "MediaServant", "icon": "server" } } diff --git a/media-webui/scripts/build-all.mjs b/media-webui/scripts/build-all.mjs index c6ee349..9346b96 100644 --- a/media-webui/scripts/build-all.mjs +++ b/media-webui/scripts/build-all.mjs @@ -12,7 +12,6 @@ const targets = { moderator: 'MediaModerator', kiosk: 'MediaKiosk', servant: 'MediaServant', - desktop: 'MediaDesktop', } const requested = process.argv.slice(2) diff --git a/media-webui/src/lib/app-config.ts b/media-webui/src/lib/app-config.ts index 0427f4b..6a19e61 100644 --- a/media-webui/src/lib/app-config.ts +++ b/media-webui/src/lib/app-config.ts @@ -238,29 +238,6 @@ const configs: Record = { }, ], }, - desktop: { - id: 'desktop', - name: 'MediaViewer Desktop', - icon: projectIcon('desktop'), - eyebrow: 'Connected player', - description: 'Control playback, funscripts, and connected devices from your desktop.', - nav: [ - { - label: 'Player', - panel: 'player', - path: '/', - icon: 'monitor-play', - description: 'Control playback and connected desktop devices.', - }, - { - label: 'Devices', - panel: 'devices', - path: '/devices', - icon: 'box', - description: 'Manage connected playback and funscript devices.', - }, - ], - }, } export function getAppConfig(id: string): AppConfig { diff --git a/media-webui/src/lib/components/AnalyzerHistory.svelte b/media-webui/src/lib/components/AnalyzerHistory.svelte index 6928301..b8dfbf8 100644 --- a/media-webui/src/lib/components/AnalyzerHistory.svelte +++ b/media-webui/src/lib/components/AnalyzerHistory.svelte @@ -1,11 +1,7 @@ - -
- -
-

{title}

-

{message}

-
-
diff --git a/media-webui/src/lib/components/PipelineFlowDiagram.svelte b/media-webui/src/lib/components/PipelineFlowDiagram.svelte index 23b40bd..31de7f9 100644 --- a/media-webui/src/lib/components/PipelineFlowDiagram.svelte +++ b/media-webui/src/lib/components/PipelineFlowDiagram.svelte @@ -1,6 +1,6 @@ - -
-
-

{title}

- {#if description}

{description}

{/if} -
-
diff --git a/media-webui/src/lib/components/SettingsDialog.svelte b/media-webui/src/lib/components/SettingsDialog.svelte index 9381092..83ba014 100644 --- a/media-webui/src/lib/components/SettingsDialog.svelte +++ b/media-webui/src/lib/components/SettingsDialog.svelte @@ -1,6 +1,6 @@ -{#if open} - -{/if} + + + diff --git a/media-webui/src/lib/components/StatusDialog.svelte b/media-webui/src/lib/components/StatusDialog.svelte deleted file mode 100644 index 8660f0a..0000000 --- a/media-webui/src/lib/components/StatusDialog.svelte +++ /dev/null @@ -1,102 +0,0 @@ - - -{#if open} - -{/if} diff --git a/media-webui/src/lib/components/StatusWidget.svelte b/media-webui/src/lib/components/StatusWidget.svelte deleted file mode 100644 index 5373b99..0000000 --- a/media-webui/src/lib/components/StatusWidget.svelte +++ /dev/null @@ -1,97 +0,0 @@ - - - - - diff --git a/media-webui/src/lib/components/WorkspacePage.svelte b/media-webui/src/lib/components/WorkspacePage.svelte index b82d6e4..e6eb851 100644 --- a/media-webui/src/lib/components/WorkspacePage.svelte +++ b/media-webui/src/lib/components/WorkspacePage.svelte @@ -3,7 +3,6 @@ import { getAppConfig, getPanelForPath, getPathForPanel } from '$lib/app-config' import AnalyzerWorkspace from '$lib/features/AnalyzerWorkspace.svelte' import ConfigWorkspace from '$lib/features/ConfigWorkspace.svelte' - import DesktopWorkspace from '$lib/features/DesktopWorkspace.svelte' import FeedWorkspace from '$lib/features/FeedWorkspace.svelte' import KioskWorkspace from '$lib/features/KioskWorkspace.svelte' import MediaTypePipeline from '$lib/features/MediaTypePipeline.svelte' @@ -82,6 +81,4 @@ {:else if app.id === 'servant'} -{:else} - {/if} diff --git a/media-webui/src/lib/components/ui/badge.svelte b/media-webui/src/lib/components/ui/badge.svelte deleted file mode 100644 index 3283d6d..0000000 --- a/media-webui/src/lib/components/ui/badge.svelte +++ /dev/null @@ -1,32 +0,0 @@ - - - - {@render children?.()} - diff --git a/media-webui/src/lib/components/ui/button.svelte b/media-webui/src/lib/components/ui/button.svelte deleted file mode 100644 index f789b46..0000000 --- a/media-webui/src/lib/components/ui/button.svelte +++ /dev/null @@ -1,43 +0,0 @@ - - - diff --git a/media-webui/src/lib/components/ui/card.svelte b/media-webui/src/lib/components/ui/card.svelte deleted file mode 100644 index 260ac67..0000000 --- a/media-webui/src/lib/components/ui/card.svelte +++ /dev/null @@ -1,14 +0,0 @@ - - -
- {@render children?.()} -
diff --git a/media-webui/src/lib/components/ui/metric.svelte b/media-webui/src/lib/components/ui/metric.svelte deleted file mode 100644 index f8a9e8c..0000000 --- a/media-webui/src/lib/components/ui/metric.svelte +++ /dev/null @@ -1,32 +0,0 @@ - - -
-

{label}

-

- {value} -

- {#if detail}

{detail}

{/if} -
diff --git a/media-webui/src/lib/features/AnalyzerWorkspace.svelte b/media-webui/src/lib/features/AnalyzerWorkspace.svelte index 595c755..06e9a68 100644 --- a/media-webui/src/lib/features/AnalyzerWorkspace.svelte +++ b/media-webui/src/lib/features/AnalyzerWorkspace.svelte @@ -2,17 +2,11 @@ import { AlertTriangle, Play, Plus, RefreshCw, Trash2 } from '@lucide/svelte' import { onMount } from 'svelte' import { SvelteSet } from 'svelte/reactivity' - import { notify } from '@gabriel20xx/web-ui' + import { Badge, Button, Card, EmptyState, Metric, notify, SectionTitle } from '@gabriel20xx/web-ui' import { del, get, post } from '$lib/api' import AnalyzerHistory from '$lib/components/AnalyzerHistory.svelte' import AnalyzerLiveStatus from '$lib/components/AnalyzerLiveStatus.svelte' import AnalyzerPipelineBreakdown from '$lib/components/AnalyzerPipelineBreakdown.svelte' - import SectionTitle from '$lib/components/SectionTitle.svelte' - import Card from '$lib/components/ui/card.svelte' - import Button from '$lib/components/ui/button.svelte' - import Badge from '$lib/components/ui/badge.svelte' - import Metric from '$lib/components/ui/metric.svelte' - import EmptyState from '$lib/components/EmptyState.svelte' import { cn } from '$lib/utils/cn' type Json = Record @@ -407,18 +401,18 @@ label="Pending" value={numeric('queued', numeric('queueLength'))} detail="Waiting for a worker" - tone="warning" + variant="warning" /> + variant="success" + />
@@ -476,18 +470,18 @@ label="Pending" value={numeric('queued', numeric('queueLength'))} detail="Waiting for a worker" - tone="warning" + variant="warning" /> + variant="success" + />
{/if}
- {schedule.enabled === false ? 'Paused' : 'Enabled'} - type StatusTone = 'neutral' | 'primary' | 'success' | 'warning' | 'danger' + type StatusTone = 'default' | 'primary' | 'success' | 'warning' | 'danger' type ConnectionStatus = { label: string; tone: StatusTone; title?: string } type MountEntry = { type: string; path: string } type TransferLimit = { uploadKbps: string; downloadKbps: string } @@ -584,7 +579,7 @@ } function statusFor(key: string): ConnectionStatus { - return statuses[key] || { label: 'Unknown', tone: 'neutral' } + return statuses[key] || { label: 'Unknown', tone: 'default' } } async function checkTarget(key: string, rawUrl: string, project: string | null, id: string) { @@ -593,7 +588,7 @@ urls = { ...urls, [id]: url } } if (!url) { - statuses = { ...statuses, [key]: { label: 'No URL', tone: 'neutral' } } + statuses = { ...statuses, [key]: { label: 'No URL', tone: 'default' } } return } @@ -845,7 +840,7 @@

The image-generation service used by MediaTools.

- {statusFor('comfyui').label} @@ -883,7 +878,7 @@ {connection.label || `External Connection ${index + 1}`}

{statusFor(`external:${connection.id}`).label} @@ -1007,13 +1002,13 @@

{labels.mediaconfig || 'MediaConfig'}

{#if labels.mediaconfig}(MediaConfig){/if} - {statusFor('mediaconfig').label}
- Self + Self
@@ -1068,7 +1063,7 @@ {#if labels[projectKey(project)]}({getInstanceLabel(project)}){/if} - {statusFor(projectKey(project)).label}
@@ -1167,7 +1162,7 @@

{labels[key] || getInstanceLabel(project)}

{#if labels[key]}({getInstanceLabel(project)}){/if} - {statusFor(key).label} + {statusFor(key).label}
diff --git a/media-webui/src/lib/features/DesktopWorkspace.svelte b/media-webui/src/lib/features/DesktopWorkspace.svelte deleted file mode 100644 index cf3f0dc..0000000 --- a/media-webui/src/lib/features/DesktopWorkspace.svelte +++ /dev/null @@ -1,99 +0,0 @@ - - -
- {#if panel === 'devices'} -
- -
-
- -
-

Serial / TCode

-

Waiting for a local driver

-
- Offline -
-
- -
-

Bluetooth devices

-

Native discovery is available after launch

-
- Offline -
-
-
- -

- No device is currently receiving output. Connect a driver from the native controls to enable playback - synchronization. -

-
-
- {:else if panel === 'settings'} - -
- -
-
- {:else} -
- -
- -
-
-
- -
-

No active media

-

Player status will appear after connection.

-
-
- -
-
- {/if} -
diff --git a/media-webui/src/lib/features/FeedWorkspace.svelte b/media-webui/src/lib/features/FeedWorkspace.svelte index 2126853..ea07413 100644 --- a/media-webui/src/lib/features/FeedWorkspace.svelte +++ b/media-webui/src/lib/features/FeedWorkspace.svelte @@ -2,10 +2,7 @@ import { page } from '$app/state' import { Film, Music2, Play } from '@lucide/svelte' import { get } from '$lib/api' - import EmptyState from '$lib/components/EmptyState.svelte' - import Badge from '$lib/components/ui/badge.svelte' - import Button from '$lib/components/ui/button.svelte' - import Card from '$lib/components/ui/card.svelte' + import { Badge, Button, Card, EmptyState } from '@gabriel20xx/web-ui' interface FeedItem { mediaKey?: string @@ -104,7 +101,7 @@ {item.title || item.name || item.filename || 'Untitled media'}

- {#if item.mediaType}{item.mediaType}{/if} + {#if item.mediaType}{item.mediaType}{/if} {#if item.category}{item.category}{/if} {#if item.filename}{item.filename}{/if}
diff --git a/media-webui/src/lib/features/KioskWorkspace.svelte b/media-webui/src/lib/features/KioskWorkspace.svelte index b73aa88..2e9f098 100644 --- a/media-webui/src/lib/features/KioskWorkspace.svelte +++ b/media-webui/src/lib/features/KioskWorkspace.svelte @@ -2,11 +2,7 @@ import { Maximize2, Pause, Play, Settings2, Wifi, WifiOff } from '@lucide/svelte' import { onMount } from 'svelte' import { get } from '$lib/api' - import SectionTitle from '$lib/components/SectionTitle.svelte' - import Card from '$lib/components/ui/card.svelte' - import Button from '$lib/components/ui/button.svelte' - import Badge from '$lib/components/ui/badge.svelte' - import Metric from '$lib/components/ui/metric.svelte' + import { Badge, Button, Card, Metric, SectionTitle } from '@gabriel20xx/web-ui' type KioskConfig = { defaultDisplayDuration?: number @@ -126,7 +122,7 @@ class="flex flex-wrap justify-end gap-2" aria-label={panel === 'kiosk' ? 'Kiosk controls' : 'Kiosk display controls'} > - {#if connected}Connected{:else}Waiting{/if}
{/if}
- sum + stage.errors, 0)} detail="Needs attention" - tone="danger" + variant="danger" />
diff --git a/media-webui/src/lib/features/ModeratorWorkspace.svelte b/media-webui/src/lib/features/ModeratorWorkspace.svelte index 114f06d..ce9a6aa 100644 --- a/media-webui/src/lib/features/ModeratorWorkspace.svelte +++ b/media-webui/src/lib/features/ModeratorWorkspace.svelte @@ -1,14 +1,8 @@ - + {@render children?.()} diff --git a/packages/web-ui/src/lib/components/Button.svelte b/packages/web-ui/src/lib/components/Button.svelte index 6c8e91d..992bf90 100644 --- a/packages/web-ui/src/lib/components/Button.svelte +++ b/packages/web-ui/src/lib/components/Button.svelte @@ -1,8 +1,9 @@ + +
+
diff --git a/packages/web-ui/src/lib/components/Metric.svelte b/packages/web-ui/src/lib/components/Metric.svelte new file mode 100644 index 0000000..cc843f3 --- /dev/null +++ b/packages/web-ui/src/lib/components/Metric.svelte @@ -0,0 +1,21 @@ + + +
+

{label}

+

{value}

+ {#if detail}

{detail}

{/if} +
diff --git a/packages/web-ui/src/lib/components/SectionTitle.svelte b/packages/web-ui/src/lib/components/SectionTitle.svelte new file mode 100644 index 0000000..8317997 --- /dev/null +++ b/packages/web-ui/src/lib/components/SectionTitle.svelte @@ -0,0 +1,8 @@ + + +
+

{title}

+ {#if description}

{description}

{/if} +
diff --git a/packages/web-ui/src/lib/components/StatusDialog.svelte b/packages/web-ui/src/lib/components/StatusDialog.svelte new file mode 100644 index 0000000..d730e70 --- /dev/null +++ b/packages/web-ui/src/lib/components/StatusDialog.svelte @@ -0,0 +1,71 @@ + + + +
+ {#if status.loading && status.level === 'checking'} +
+ +
+ {#each [{ label: 'Liveness', probe: status.health }, { label: 'Readiness / database', probe: status.readiness }] as item (item.label)} +
+ {item.label} + {probeLabel(item.probe)} +
+ {/each} +
+ + {#if status.health?.service || status.readiness?.service} +

Service: {status.health?.service || status.readiness?.service}

+ {/if} + + {#snippet footer()} + + + {/snippet} +
diff --git a/packages/web-ui/src/lib/components/StatusWidget.svelte b/packages/web-ui/src/lib/components/StatusWidget.svelte new file mode 100644 index 0000000..2340ee0 --- /dev/null +++ b/packages/web-ui/src/lib/components/StatusWidget.svelte @@ -0,0 +1,103 @@ + + + + + diff --git a/packages/web-ui/src/lib/index.ts b/packages/web-ui/src/lib/index.ts index 8f92ccc..42599a5 100644 --- a/packages/web-ui/src/lib/index.ts +++ b/packages/web-ui/src/lib/index.ts @@ -6,12 +6,17 @@ export { default as Badge } from './components/Badge.svelte'; export { default as Button } from './components/Button.svelte'; export { default as Card } from './components/Card.svelte'; export { default as Dialog } from './components/Dialog.svelte'; +export { default as EmptyState } from './components/EmptyState.svelte'; export { default as Header } from './components/Header.svelte'; +export { default as Metric } from './components/Metric.svelte'; export { default as NotificationStack } from './components/NotificationStack.svelte'; export { default as PageHeader } from './components/PageHeader.svelte'; export { default as Pagination } from './components/Pagination.svelte'; export { default as ProfileDialog } from './components/ProfileDialog.svelte'; +export { default as SectionTitle } from './components/SectionTitle.svelte'; export { default as SettingsDialog } from './components/SettingsDialog.svelte'; +export { default as StatusDialog } from './components/StatusDialog.svelte'; +export { default as StatusWidget } from './components/StatusWidget.svelte'; export { default as TotpSettings } from './components/TotpSettings.svelte'; export { default as UserManagement } from './components/UserManagement.svelte'; export { notifications, notify } from './notifications.svelte'; @@ -27,6 +32,9 @@ export type { NavItem, ProfileUpdateInput, ManagedUser, + StatusLevel, + StatusProbe, + StatusSnapshot, UserCreateInput, UserCreateRequest, UserDeleteRequest, diff --git a/packages/web-ui/src/lib/styles.css b/packages/web-ui/src/lib/styles.css index 49fcf66..5326567 100644 --- a/packages/web-ui/src/lib/styles.css +++ b/packages/web-ui/src/lib/styles.css @@ -285,6 +285,12 @@ font-weight: 650; } +.sc-badge[data-variant="primary"] { + color: var(--sc-primary-fg); + background: var(--sc-primary); + border-color: transparent; +} + .sc-badge[data-variant="success"] { color: var(--sc-success-fg); background: var(--sc-success); @@ -380,6 +386,16 @@ background: var(--sc-danger-hover); } +.sc-button-outline { + color: var(--sc-fg); + background: transparent; + border-color: var(--sc-border); +} + +.sc-button-outline:hover:not(:disabled) { + background: var(--sc-surface-hover); +} + .sc-button-sm { min-height: 2rem; padding: 0.45rem 0.75rem; @@ -391,6 +407,187 @@ padding: 0.75rem 1.25rem; } +.sc-button-icon { + min-height: 2.5rem; + width: 2.5rem; + padding: 0; +} + +.sc-empty-state { + display: flex; + min-height: 10rem; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 0.75rem; + padding: 2rem 1.25rem; + text-align: center; + border: 1px dashed var(--sc-border); + border-radius: var(--sc-radius-lg); + background: color-mix(in srgb, var(--sc-surface) 50%, transparent); +} + +.sc-empty-state-icon { + color: var(--sc-muted-fg); +} + +.sc-empty-state-title { + margin: 0; + font-size: 0.9rem; + font-weight: 600; + color: var(--sc-fg); +} + +.sc-empty-state-message { + margin: 0.25rem 0 0; + max-width: 24rem; + font-size: 0.8125rem; + color: var(--sc-muted-fg); +} + +.sc-section-title { + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 0.75rem; +} + +.sc-section-title h2 { + margin: 0; + font-size: 0.9rem; + font-weight: 650; + color: var(--sc-fg); +} + +.sc-section-title p { + margin: 0.25rem 0 0; +} + +.sc-metric { + padding: 1rem; + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-lg); + background: var(--sc-surface); +} + +.sc-metric-label { + margin: 0; + font-size: 0.6875rem; + font-weight: 650; + letter-spacing: 0.06em; + text-transform: uppercase; + color: var(--sc-muted-fg); +} + +.sc-metric-value { + margin: 0.5rem 0 0; + font-size: 1.5rem; + font-weight: 650; + letter-spacing: -0.01em; + color: var(--sc-fg); +} + +.sc-metric-value[data-variant="primary"] { + color: var(--sc-primary); +} + +.sc-metric-value[data-variant="success"] { + color: var(--sc-success); +} + +.sc-metric-value[data-variant="warning"] { + color: var(--sc-warning); +} + +.sc-metric-value[data-variant="danger"] { + color: var(--sc-danger); +} + +.sc-metric-detail { + margin: 0.25rem 0 0; + font-size: 0.8125rem; + color: var(--sc-muted-fg); +} + +.sc-status-icon { + color: var(--sc-muted-fg); +} + +.sc-status-summary[data-level="healthy"] .sc-status-icon, +.sc-status-summary[data-level="healthy"] .sc-status-summary-label { + color: var(--sc-success); +} + +.sc-status-summary[data-level="degraded"] .sc-status-icon, +.sc-status-summary[data-level="degraded"] .sc-status-summary-label { + color: var(--sc-warning); +} + +.sc-status-summary[data-level="offline"] .sc-status-icon, +.sc-status-summary[data-level="offline"] .sc-status-summary-label { + color: var(--sc-danger); +} + +.sc-status-spin { + animation: sc-spin 900ms linear infinite; +} + +@keyframes sc-spin { + to { + transform: rotate(360deg); + } +} + +.sc-status-summary { + display: flex; + align-items: center; + gap: 0.75rem; + margin-bottom: 1.25rem; + padding: 0.75rem; + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-md); + background: var(--sc-surface); +} + +.sc-status-summary-label { + font-weight: 650; +} + +.sc-status-summary-time { + margin-left: auto; + font-size: 0.75rem; + color: var(--sc-muted-fg); +} + +.sc-status-probes { + display: flex; + flex-direction: column; + gap: 0.5rem; + font-size: 0.875rem; +} + +.sc-status-probe { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1rem; + padding: 0.5rem 0.75rem; + border: 1px solid var(--sc-border); + border-radius: var(--sc-radius-sm); +} + +.sc-status-probe span[data-ok="true"] { + color: var(--sc-success); +} + +.sc-status-probe span[data-ok="false"] { + color: var(--sc-danger); +} + +.sc-status-service { + margin-top: 1rem; +} + .sc-button-full { width: 100%; } diff --git a/packages/web-ui/src/lib/types.ts b/packages/web-ui/src/lib/types.ts index 0ab2f73..fed9cda 100644 --- a/packages/web-ui/src/lib/types.ts +++ b/packages/web-ui/src/lib/types.ts @@ -91,3 +91,21 @@ export interface AboutLink { } export type ContentSnippet = Snippet; + +export type StatusLevel = "checking" | "healthy" | "degraded" | "offline"; + +export interface StatusProbe { + path: string; + ok: boolean; + httpStatus: number | null; + service: string | null; + error: string | null; +} + +export interface StatusSnapshot { + level: StatusLevel; + health: StatusProbe | null; + readiness: StatusProbe | null; + checkedAt: string | null; + loading: boolean; +}