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 <noreply@anthropic.com>
This commit is contained in:
Gabriel20xxandClaude Sonnet 5 committed 2026-08-31 22:19:58 +02:00
1 parent acde180086
commit 38a349eb52
20 files changed
+74 -55

No files matched your search

+1 -1
View File
@@ -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
+2 -2
View File
@@ -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.
+19
View File
@@ -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.
+1 -1
View File
@@ -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")),
@@ -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.
@@ -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) {
+6 -6
View File
@@ -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"} {
+1 -1
View File
@@ -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.
@@ -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
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
+7 -7
View File
@@ -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" }
}
+7 -7
View File
@@ -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)
+7 -7
View File
@@ -9,7 +9,7 @@ function projectIcon(id: AppId): ProjectIconName {
const configs: Record<AppId, AppConfig> = {
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<AppId, AppConfig> = {
},
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<AppId, AppConfig> = {
},
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<AppId, AppConfig> = {
},
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<AppId, AppConfig> = {
},
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<AppId, AppConfig> = {
},
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<AppId, AppConfig> = {
},
desktop: {
id: 'desktop',
name: 'Beacon',
name: 'MediaViewer Desktop',
icon: projectIcon('desktop'),
eyebrow: 'Connected player',
description: 'Control playback, funscripts, and connected devices from your desktop.',
@@ -842,7 +842,7 @@
<div class="flex flex-wrap items-center justify-between gap-3">
<div>
<p class="text-sm font-semibold text-fg">ComfyUI</p>
<p class="mt-1 text-xs text-muted-fg">The image-generation service used by Forge.</p>
<p class="mt-1 text-xs text-muted-fg">The image-generation service used by MediaTools.</p>
</div>
<div class="flex items-center gap-2">
<Badge tone={statusFor('comfyui').tone} title={statusFor('comfyui').title}
@@ -867,7 +867,7 @@
<div class="flex flex-wrap items-start justify-between gap-3">
<SectionTitle
title="External connections"
description="Optional services can pause their queue and use Porter bandwidth limits."
description="Optional services can pause their queue and use MediaServant bandwidth limits."
/>
<Button variant="secondary" size="sm" onclick={addExternal}><Plus class="size-4" />Add connection</Button>
</div>
@@ -1046,8 +1046,8 @@
<Card class="space-y-5">
<div class="flex flex-wrap items-start justify-between gap-3">
<SectionTitle
title="Porter instances"
description="Configure the URL for each running Porter instance. All services use these URLs to proxy media requests."
title="MediaServant instances"
description="Configure the URL for each running MediaServant instance. All services use these URLs to proxy media requests."
/>
<Button variant="secondary" size="sm" onclick={addServant}><Plus class="size-4" />Add instance</Button>
</div>
@@ -1111,7 +1111,7 @@
/>
</label>
<label class="block text-xs font-medium text-muted-fg">
Porter URL
MediaServant URL
<input
type="text"
value={urls[projectKey(project)] || ''}
@@ -1221,7 +1221,7 @@
{#if !isNoMounts(project)}
<div class="grid gap-3 sm:grid-cols-2">
<label class="block text-xs font-medium text-muted-fg">
Porter Upload Limit (KB/s)
MediaServant Upload Limit (KB/s)
<input
type="number"
min="0"
@@ -1233,7 +1233,7 @@
/>
</label>
<label class="block text-xs font-medium text-muted-fg">
Porter Download Limit (KB/s)
MediaServant Download Limit (KB/s)
<input
type="number"
min="0"
@@ -1367,7 +1367,7 @@
<div>
<p class="text-sm font-medium text-fg">Mounts</p>
<p class="mt-1 text-xs text-muted-fg">
Shared file roots are configured in the Mounts workspace and resolved by Porter.
Shared file roots are configured in the Mounts workspace and resolved by MediaServant.
</p>
</div>
</div>
@@ -70,11 +70,11 @@
<Card class="space-y-5"
><SectionTitle
title="Embedded player"
description="The desktop shell embeds Playhouse when a server is connected."
description="The desktop shell embeds MediaViewer when a server is connected."
/>
<div class="flex min-h-[420px] items-center justify-center rounded-lg border border-dashed border-border bg-bg">
<EmptyState
title="Connect a Playhouse server"
title="Connect a MediaViewer server"
message="Enter a server URL in the native desktop panel to load the library and player."
/>
</div></Card
@@ -166,7 +166,7 @@
d="M8 21h8M12 17v4M7 9h.01M11 9h6M7 13h10"
/></svg
>
<p class="text-sm">Waiting for the next image from Porter.</p>
<p class="text-sm">Waiting for the next image from MediaServant.</p>
<p class="text-xs text-white/40">The canvas will update automatically over WebSocket.</p>
</div>{/if}
<div
@@ -463,7 +463,7 @@
Loading media…
</p>{:else if media.length === 0}<EmptyState
title="No catalog media found"
message="Lookout outputs will appear once the catalog synchronization has data."
message="MediaAnalyzer outputs will appear once the catalog synchronization has data."
/>{:else}<div class="overflow-x-auto">
<table class="w-full min-w-[720px] text-left">
<thead
@@ -952,7 +952,7 @@
<div class="flex items-center justify-between gap-3">
<div>
<h2 class="text-sm font-medium text-fg">Sync Info</h2>
<p class="mt-1 text-xs text-muted-fg">Connect this player to other Playhouse endpoints.</p>
<p class="mt-1 text-xs text-muted-fg">Connect this player to other MediaViewer endpoints.</p>
</div>
{#if syncConnected}<Badge tone="success"><Wifi class="mr-1 size-3" />Connected</Badge>{:else}<Badge
tone="warning"><WifiOff class="mr-1 size-3" />Disconnected</Badge
+1 -1
View File
@@ -1,4 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#5b8cff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" role="img" aria-labelledby="favicon-title">
<title id="favicon-title">Playhouse</title>
<title id="favicon-title">MediaViewer</title>
<path d="M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z" />
</svg>

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 373 B