From 38a349eb52b787e420a71b3a1a4ade636471cd36 Mon Sep 17 00:00:00 2001 From: Gabriel20xx Date: Mon, 31 Aug 2026 22:19:58 +0200 Subject: [PATCH] Fix media-backend/media-webui: re-copy from post-revert MediaCollection The original MediaEngine extraction (later folded into this repo) had been done BEFORE the owner's decision to revert the MediaViewer/Forge/ etc. rename, and was never re-extracted afterward like the other 7 service repos were - it silently carried stale renamed-era text (e.g. 'Porter' instead of 'MediaServant') into Go doc comments, WebUI prose, project-icons.json, and app-config.ts. Re-copied both directories fresh from the current (correctly reverted) MediaCollection/backend and MediaCollection/WebUI, then re-applied the go.mod replace-directive fix and re-added SECURITY_AUDIT.md (also newly migrated from MediaCollection root - a real deployment security checklist that would otherwise have been lost when MediaCollection is deleted). Co-Authored-By: Claude Sonnet 5 --- media-backend/.env.example | 2 +- media-backend/README.md | 4 ++-- media-backend/SECURITY_AUDIT.md | 19 +++++++++++++++++++ media-backend/internal/config/config.go | 2 +- .../database/migrations/001_initial.sql | 2 +- .../internal/server/admin_storage.go | 10 +++++----- media-backend/internal/server/analyzer.go | 12 ++++++------ media-backend/internal/server/analyzer_ai.go | 2 +- .../internal/server/servant_client.go | 2 +- media-backend/internal/server/server.go | 2 +- media-backend/internal/server/workflows.go | 2 +- media-webui/project-icons.json | 14 +++++++------- media-webui/scripts/build-all.mjs | 14 +++++++------- media-webui/src/lib/app-config.ts | 14 +++++++------- .../src/lib/features/ConfigWorkspace.svelte | 16 ++++++++-------- .../src/lib/features/DesktopWorkspace.svelte | 4 ++-- .../src/lib/features/KioskWorkspace.svelte | 2 +- .../lib/features/ModeratorWorkspace.svelte | 2 +- media-webui/src/lib/features/VideoPage.svelte | 2 +- media-webui/static/favicon.svg | 2 +- 20 files changed, 74 insertions(+), 55 deletions(-) create mode 100644 media-backend/SECURITY_AUDIT.md diff --git a/media-backend/.env.example b/media-backend/.env.example index 023fa11..d5489c1 100644 --- a/media-backend/.env.example +++ b/media-backend/.env.example @@ -9,7 +9,7 @@ OUTPUT_DIR=../output DOWNLOADS_DIR=../downloads THUMBNAIL_DIR=../thumbnails MODEL_CACHE_DIR=../models -WORKFLOWS_DIR=../Forge/public/workflows +WORKFLOWS_DIR=../MediaTools/public/workflows FFMPEG_PATH=ffmpeg FFPROBE_PATH=ffprobe YT_DLP_PATH=yt-dlp diff --git a/media-backend/README.md b/media-backend/README.md index 01c78d3..976b85c 100644 --- a/media-backend/README.md +++ b/media-backend/README.md @@ -14,7 +14,7 @@ go run ./cmd/mediacollectiond Important settings: -- `MEDIA_ROOTS` is a comma- or semicolon-separated list of media roots. Porter also walks +- `MEDIA_ROOTS` is a comma- or semicolon-separated list of media roots. MediaServant also walks every path saved under a `media`/`images`/`videos`/`audios`/`funscripts` mount in MediaConfig's Mounts workspace (the `configured_mounts` setting) regardless of which project's tab it was entered under - see `effectiveMediaRoots` in `internal/server/admin_storage.go`. `MEDIA_ROOTS` @@ -23,7 +23,7 @@ Important settings: - `WORKFLOWS_DIR` points to the built-in ComfyUI workflow definitions. - `FFMPEG_PATH`, `FFPROBE_PATH`, and `YT_DLP_PATH` select workflow executables. - `COMFYUI_URL` configures the generator service. -- `SERVANT_URL` is only the bootstrap fallback for Porter's URL - once configured through +- `SERVANT_URL` is only the bootstrap fallback for MediaServant's URL - once configured through MediaConfig it's read from the `mediaservant_url` row in the `settings` table instead (see `servantBaseURL` in `internal/server/servant_client.go`). - `INTERNAL_SERVICE_SECRET` protects service-to-service mount and media-proxy APIs. diff --git a/media-backend/SECURITY_AUDIT.md b/media-backend/SECURITY_AUDIT.md new file mode 100644 index 0000000..e484226 --- /dev/null +++ b/media-backend/SECURITY_AUDIT.md @@ -0,0 +1,19 @@ +# MediaCollection security notes + +The backend rewrite consolidates the security boundary in `internal/`. + +Implemented controls include: + +- bcrypt passwords, PostgreSQL cookie sessions, TOTP verification, role checks, and disabled-user checks; +- explicit CORS and WebSocket origin validation, security headers, and bounded request bodies; +- additive PostgreSQL migrations with a startup advisory lock; +- traversal, absolute-path, drive-path, and symlink-escape protection for every configured media root; +- fixed ffmpeg argument construction and bounded workflow workers; +- HTTPS-only downloader URLs with credential, private-IP, link-local, metadata-host, and DNS-rebinding checks; +- internal-service secret checks for mount, download, reload, upload, and catalog mutation routes; +- non-root Docker images and no Node server runtime. + +Before deployment, set a unique `INTERNAL_SERVICE_SECRET`, use a strong database password, configure +`CORS_ORIGIN` to the real frontend origin, and enable TLS so `COOKIE_SECURE` can remain enabled. +Review the canonical Go routes when adding a capability; do not reintroduce the removed JavaScript +server paths or Socket.IO transport. diff --git a/media-backend/internal/config/config.go b/media-backend/internal/config/config.go index af30d48..0b98295 100644 --- a/media-backend/internal/config/config.go +++ b/media-backend/internal/config/config.go @@ -85,7 +85,7 @@ func Load() (*Config, error) { MediaRoots: roots, InputRoot: filepath.Clean(envOr("INPUT_DIR", "./input")), CopyRoot: filepath.Clean(envOr("UPLOAD_COPY_DIR", "./copy")), - WorkflowsRoot: filepath.Clean(envOr("WORKFLOWS_DIR", filepath.Join("..", "Forge", "public", "workflows"))), + WorkflowsRoot: filepath.Clean(envOr("WORKFLOWS_DIR", filepath.Join("..", "MediaTools", "public", "workflows"))), ThumbnailRoot: filepath.Clean(envOr("THUMBNAIL_DIR", "./thumbnails")), OutputRoot: filepath.Clean(envOr("OUTPUT_DIR", "./output")), DownloadsRoot: filepath.Clean(envOr("DOWNLOADS_DIR", "./downloads")), diff --git a/media-backend/internal/database/migrations/001_initial.sql b/media-backend/internal/database/migrations/001_initial.sql index 9ab84df..bc54631 100644 --- a/media-backend/internal/database/migrations/001_initial.sql +++ b/media-backend/internal/database/migrations/001_initial.sql @@ -311,7 +311,7 @@ CREATE INDEX IF NOT EXISTS media_analysis_tasks_status_idx ON media_analysis_tas -- to make repeated analysis runs idempotent instead of piling up duplicate tag rows. CREATE UNIQUE INDEX IF NOT EXISTS media_tags_ai_tag_unique ON media_tags (media_key, tag) WHERE user_id IS NULL; --- Speeds up the Lookout dashboard/pipelines/history/live-status queries: analyzerStats and +-- Speeds up the MediaAnalyzer dashboard/pipelines/history/live-status queries: analyzerStats and -- analyzerPipelineBreakdown group active media by type (and join it against thumbnails), and -- analyzerHistory sorts media_worker_jobs by queued_at with no status filter, none of which the -- existing media/media_worker_jobs indexes above actually cover. diff --git a/media-backend/internal/server/admin_storage.go b/media-backend/internal/server/admin_storage.go index 2471ac6..db08f38 100644 --- a/media-backend/internal/server/admin_storage.go +++ b/media-backend/internal/server/admin_storage.go @@ -213,7 +213,7 @@ func (s *Server) configuredMounts(ctx context.Context) map[string][]mountEntry { } // mountMappings returns each project's mount configuration as project -> mount type -> path(s), -// the shape /mounts/resolve and /mounts/paths (and Porter's own "Mount health" panel via +// the shape /mounts/resolve and /mounts/paths (and MediaServant's own "Mount health" panel via // /mounts) expect. configured_mounts is the live source and wins per-project when present; // mounts_path_mappings is an older format nothing has written since the Mounts workspace moved // to configured_mounts, kept only so a deployment that hasn't resaved its mounts since upgrading @@ -275,8 +275,8 @@ func (s *Server) mountMappings(ctx context.Context) map[string]any { // opposed to a project-specific working directory like "downloads", "generated", // "thumbnails", or "models", which have their own dedicated Root config fields instead and // are deliberately left out here. A path is entered under whichever project's tab happens to -// need it (Lookout's "images"/"videos"/"audios", Playhouse/Marquee's "media", ...) -// but they're all describing locations Porter itself has to walk, since it's the only +// need it (MediaAnalyzer's "images"/"videos"/"audios", MediaViewer/MediaKiosk's "media", ...) +// but they're all describing locations MediaServant itself has to walk, since it's the only // service with the volume mounted - see effectiveMediaRoots. var mediaLibraryMountTypes = map[string]bool{ "media": true, "images": true, "videos": true, "audios": true, "funscripts": true, @@ -575,7 +575,7 @@ func (s *Server) writeServantFiles(w http.ResponseWriter, r *http.Request, recen if recent { sort.Slice(files, func(i, j int) bool { return files[i].Mtime > files[j].Mtime }) } - // Internal callers (e.g. Lookout discovery) need to list an entire real-sized library + // Internal callers (e.g. MediaAnalyzer discovery) need to list an entire real-sized library // in one pass; the public 1000-item cap stays in place for anyone without the shared secret. maxLimit := 1000 if s.cfg.InternalServiceSecret != "" && r.Header.Get("X-Internal-Auth") == s.cfg.InternalServiceSecret { @@ -785,7 +785,7 @@ func (s *Server) servantStore(w http.ResponseWriter, r *http.Request) { } // resolveStoreFile is Servant's own local-filesystem lookup for /api/store, which catalogs a -// file Forge already pushed into one of Servant's mounts (InputRoot, MediaRoots, +// file MediaTools already pushed into one of Servant's mounts (InputRoot, MediaRoots, // DownloadsRoot, OutputRoot) - unlike everything else in this file, it's called with a path that // isn't necessarily under MediaRoots, so it can't just use resolveMediaPath. func (s *Server) resolveStoreFile(value string) (string, error) { diff --git a/media-backend/internal/server/analyzer.go b/media-backend/internal/server/analyzer.go index 0152676..eceb025 100644 --- a/media-backend/internal/server/analyzer.go +++ b/media-backend/internal/server/analyzer.go @@ -147,7 +147,7 @@ func (s *Server) analyzerStatus(w http.ResponseWriter, r *http.Request) { running := clear.Running || scan.Running || thumbnail.Running || analysis.Running || processing > 0 // scan/clear have no dedicated status endpoint of their own (thumbnail/analysis do, via // generate/status and analyze/status) - this is the only place their LastError ever reaches - // the UI, so a discover/metadata/cleanup run that fails fast (e.g. Porter unreachable) + // the UI, so a discover/metadata/cleanup run that fails fast (e.g. MediaServant unreachable) // is reported here instead of just looking like it silently reverted to idle. lastError := firstNonEmpty(scan.LastError, clear.LastError) @@ -1299,16 +1299,16 @@ func (s *Server) scanMediaFiles(selectedTypes map[string]bool) { files, err := s.servantListFiles(ctx, "", false, 0) if err != nil { log.Printf("analyzer: discovery scan: failed to list files: %v", err) - runErr = fmt.Errorf("could not reach Porter to list files: %w", err) + runErr = fmt.Errorf("could not reach MediaServant to list files: %w", err) return } - // Porter reachable but reporting an empty library is otherwise indistinguishable from + // MediaServant reachable but reporting an empty library is otherwise indistinguishable from // a successful no-op run - every existing file re-indexes (and increments FilesIndexed) on // every scan, so a real library can never legitimately finish at zero. Flag it instead of // letting "discovery started" silently revert to idle with nothing to show for it. if len(files) == 0 { - log.Printf("analyzer: discovery scan: Porter reported zero files") - runErr = fmt.Errorf("Porter reported no files under its configured media root(s) - check the Mounts settings in MediaConfig") + log.Printf("analyzer: discovery scan: MediaServant reported zero files") + runErr = fmt.Errorf("MediaServant reported no files under its configured media root(s) - check the Mounts settings in MediaConfig") return } for _, file := range files { @@ -1501,7 +1501,7 @@ func hasFunscriptSidecar(filePath string) bool { } // funscriptSidecarExists is hasFunscriptSidecar for callers without local filesystem access -// (Lookout) - it checks for the sidecar on Servant instead of statting a local path. +// (MediaAnalyzer) - it checks for the sidecar on Servant instead of statting a local path. func (s *Server) funscriptSidecarExists(ctx context.Context, key string) bool { base := strings.TrimSuffix(key, filepath.Ext(key)) for _, candidate := range []string{base + ".funscript", base + ".json"} { diff --git a/media-backend/internal/server/analyzer_ai.go b/media-backend/internal/server/analyzer_ai.go index f901bc7..21c850d 100644 --- a/media-backend/internal/server/analyzer_ai.go +++ b/media-backend/internal/server/analyzer_ai.go @@ -433,7 +433,7 @@ type analysisSidecarRequest struct { } // callAnalyzerModelsService calls the AnalyzerModels sidecar (a separate process in the same -// container, not baked into this binary - see ANALYZER_MODELS_URL and Lookout/Dockerfile), +// container, not baked into this binary - see ANALYZER_MODELS_URL and MediaAnalyzer/Dockerfile), // the same way executeGeneration already calls out to ComfyUI for image generation. Video frames // are analyzed through the image endpoint since by the time this runs the video has already been // reduced to a still frame. diff --git a/media-backend/internal/server/servant_client.go b/media-backend/internal/server/servant_client.go index f51f73f..4b94c3b 100644 --- a/media-backend/internal/server/servant_client.go +++ b/media-backend/internal/server/servant_client.go @@ -1,6 +1,6 @@ package server -// Servant client: every non-Servant service serves and stores media by calling Porter's +// Servant client: every non-Servant service serves and stores media by calling MediaServant's // HTTP API through the helpers in this file instead of touching MediaRoots/ThumbnailRoot/ // OutputRoot/DownloadsRoot/InputRoot/CopyRoot locally. Servant's own handlers keep using those // roots directly (see media.go, admin_storage.go) - this file is never called from Servant's diff --git a/media-backend/internal/server/server.go b/media-backend/internal/server/server.go index 5ade02b..f3f08db 100644 --- a/media-backend/internal/server/server.go +++ b/media-backend/internal/server/server.go @@ -129,7 +129,7 @@ type scanState struct { Total int64 StartedAt *time.Time // LastError survives the end-of-run reset (unlike every other field here) so a run that - // failed fast - e.g. Porter unreachable - doesn't just look like it silently reverted + // failed fast - e.g. MediaServant unreachable - doesn't just look like it silently reverted // to idle; analyzerStatus reports it until the next run overwrites or clears it. LastError string } diff --git a/media-backend/internal/server/workflows.go b/media-backend/internal/server/workflows.go index 757e241..0029e34 100644 --- a/media-backend/internal/server/workflows.go +++ b/media-backend/internal/server/workflows.go @@ -441,7 +441,7 @@ func firstString(values map[string]any, keys ...string) string { // workflowFileServantPaths mirrors the search order resolveWorkflowFile used to walk locally // (InputRoot, MediaRoots, DownloadsRoot, OutputRoot) but as Servant-side mount prefixes, since -// Forge no longer has any of those roots mounted on its own filesystem. +// MediaTools no longer has any of those roots mounted on its own filesystem. var workflowFileServantPaths = []string{"/mount/inputs/", "/media/", "/media/downloads/", "/mount/generated/"} // fetchWorkflowFileFromServant locates a converter input under any of Servant's mounts and diff --git a/media-webui/project-icons.json b/media-webui/project-icons.json index 0b3fa19..efa1845 100644 --- a/media-webui/project-icons.json +++ b/media-webui/project-icons.json @@ -1,10 +1,10 @@ { - "viewer": { "name": "Playhouse", "icon": "play" }, - "tools": { "name": "Forge", "icon": "wand-sparkles" }, - "analyzer": { "name": "Lookout", "icon": "scan-search" }, + "viewer": { "name": "MediaViewer", "icon": "play" }, + "tools": { "name": "MediaTools", "icon": "wand-sparkles" }, + "analyzer": { "name": "MediaAnalyzer", "icon": "scan-search" }, "config": { "name": "MediaConfig", "icon": "settings-2" }, - "moderator": { "name": "Warden", "icon": "shield-check" }, - "kiosk": { "name": "Marquee", "icon": "image" }, - "servant": { "name": "Porter", "icon": "server" }, - "desktop": { "name": "Beacon", "icon": "monitor-play" } + "moderator": { "name": "MediaModerator", "icon": "shield-check" }, + "kiosk": { "name": "MediaKiosk", "icon": "image" }, + "servant": { "name": "MediaServant", "icon": "server" }, + "desktop": { "name": "MediaViewer Desktop", "icon": "monitor-play" } } diff --git a/media-webui/scripts/build-all.mjs b/media-webui/scripts/build-all.mjs index d50125d..c6ee349 100644 --- a/media-webui/scripts/build-all.mjs +++ b/media-webui/scripts/build-all.mjs @@ -5,14 +5,14 @@ import { spawn } from 'node:child_process' const webUiDir = path.resolve(import.meta.dirname, '..') const collectionDir = path.resolve(webUiDir, '..') const targets = { - viewer: 'Playhouse', - tools: 'Forge', - analyzer: 'Lookout', + viewer: 'MediaViewer', + tools: 'MediaTools', + analyzer: 'MediaAnalyzer', config: 'MediaConfig', - moderator: 'Warden', - kiosk: 'Marquee', - servant: 'Porter', - desktop: 'Beacon', + 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 5511690..0427f4b 100644 --- a/media-webui/src/lib/app-config.ts +++ b/media-webui/src/lib/app-config.ts @@ -9,7 +9,7 @@ function projectIcon(id: AppId): ProjectIconName { const configs: Record = { viewer: { id: 'viewer', - name: 'Playhouse', + name: 'MediaViewer', icon: projectIcon('viewer'), eyebrow: 'Immersive media library', description: 'Browse, search, and play your media collection from one calm workspace.', @@ -46,7 +46,7 @@ const configs: Record = { }, tools: { id: 'tools', - name: 'Forge', + name: 'MediaTools', icon: projectIcon('tools'), eyebrow: 'Media workflow studio', description: 'Generate, download, convert, and schedule media jobs in one place.', @@ -90,7 +90,7 @@ const configs: Record = { }, analyzer: { id: 'analyzer', - name: 'Lookout', + name: 'MediaAnalyzer', icon: projectIcon('analyzer'), eyebrow: 'Processing operations', description: 'Monitor discovery and define per-type processing pipelines and automation queues.', @@ -171,7 +171,7 @@ const configs: Record = { }, moderator: { id: 'moderator', - name: 'Warden', + name: 'MediaModerator', icon: projectIcon('moderator'), eyebrow: 'Administration and safety', description: 'Review users, media, tags, visibility, and platform health.', @@ -201,7 +201,7 @@ const configs: Record = { }, kiosk: { id: 'kiosk', - name: 'Marquee', + name: 'MediaKiosk', icon: projectIcon('kiosk'), eyebrow: 'Ambient display', description: 'Show the latest collection output in a focused, full-screen canvas.', @@ -217,7 +217,7 @@ const configs: Record = { }, servant: { id: 'servant', - name: 'Porter', + name: 'MediaServant', icon: projectIcon('servant'), eyebrow: 'Storage and delivery', description: 'Inspect mounts, file activity, bandwidth, and media delivery health.', @@ -240,7 +240,7 @@ const configs: Record = { }, desktop: { id: 'desktop', - name: 'Beacon', + name: 'MediaViewer Desktop', icon: projectIcon('desktop'), eyebrow: 'Connected player', description: 'Control playback, funscripts, and connected devices from your desktop.', diff --git a/media-webui/src/lib/features/ConfigWorkspace.svelte b/media-webui/src/lib/features/ConfigWorkspace.svelte index ffcaa75..fdb7327 100644 --- a/media-webui/src/lib/features/ConfigWorkspace.svelte +++ b/media-webui/src/lib/features/ConfigWorkspace.svelte @@ -842,7 +842,7 @@

ComfyUI

-

The image-generation service used by Forge.

+

The image-generation service used by MediaTools.

@@ -1046,8 +1046,8 @@
@@ -1111,7 +1111,7 @@ />
diff --git a/media-webui/src/lib/features/DesktopWorkspace.svelte b/media-webui/src/lib/features/DesktopWorkspace.svelte index e6ca7b7..cf3f0dc 100644 --- a/media-webui/src/lib/features/DesktopWorkspace.svelte +++ b/media-webui/src/lib/features/DesktopWorkspace.svelte @@ -70,11 +70,11 @@
-

Waiting for the next image from Porter.

+

Waiting for the next image from MediaServant.

The canvas will update automatically over WebSocket.

{/if}
{:else if media.length === 0}{:else}

Sync Info

-

Connect this player to other Playhouse endpoints.

+

Connect this player to other MediaViewer endpoints.

{#if syncConnected}Connected{:else}Disconnected - Playhouse + MediaViewer