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