Files
Showy/docs-vault/Discovery Videos.md
X4Lo eb3a12f6cb Add Discovery Videos feature
Let users upload videos, tag them with one or more entries, and watch
them from a new Discovery Videos page.

Backend:
- Add Video and VideoEntry models and relations
- Add video controller and /video routes
- Add video thumbnail generation service (ffmpeg-static)
- Add video upload storage location and config

Frontend:
- Add DiscoveryVideosPage with sidebar link and route
- Add AddVideoDialog, VideoDropzone, EntryMultiSelect, VideoCard
  and VideoPlayerDialog components
- Add discoveryVideos API client and useDiscoveryVideos hook
- Add format helpers, video types and normalizers
- Add skeleton for the page

Docs:
- Document the feature in docs-vault
2026-11-03 15:57:53 +00:00

5.5 KiB

title, tags, aliases
title tags aliases
Discovery Videos
feature
frontend
backend
videos
Videos
Saved Videos
Video Vault

Discovery Videos

Personal video vault page — upload local videos (recommendations, anything worth watching later), add a description, and link them to one or more Library entries.

Route: /discovery-videos (sidebar label: "Discover")

[!note] Naming This page is distinct from Pages#DiscoverPage, which is the TMDB browse page at /discover/:category.


Overview

Responsibilities:

  • Upload video files via drag & drop (up to 10 at once)
  • Store a description per upload
  • Link videos to one or many library entries (M:N)
  • Display all saved videos in a lazy-loaded grid with inline playback
  • Edit / delete videos (deletion also removes the file from disk)

Key Flows:

  1. Upload: AddVideoDialog → drop files → description + entry multi-select → POST /discovery-videos (multipart) → files stored to data/videos/ with UUID names
  2. Browse: DiscoveryVideosPage → GET /discovery-videos?page=&limit= (24/page) → infinite scroll via IntersectionObserver
  3. Play: clicking a card opens VideoPlayerDialog — the video plays in the dialog; ↑/↓ (and ←/→ when the player isn't focused) navigate to the previous/next video. Streamed via GET /discovery-videos/:id/stream with HTTP Range support
  4. Thumbnails (on demand): cards always request GET /discovery-videos/:id/thumbnail; when no thumbnail exists yet, the endpoint generates it (ffmpeg frame at 1s) and serves it in the same response — nothing is generated eagerly or at startup

Entry linking UX: the picker in AddVideoDialog lists entries only once the user starts typing (debounced 250 ms) — the full library is never rendered at once.


Lazy Loading & Performance

Layer Mechanism
Route React.lazy() + <Suspense> with DiscoveryVideosSkeleton
Data Paginated API + useInfiniteQuery + IntersectionObserver sentinel (rootMargin: "400px") — only metadata travels, never video bytes
Thumbnails <img loading="lazy"> requesting the thumbnail endpoint — generated on demand on first request (no eager/startup generation), deduped + limited to 2 concurrent ffmpeg jobs
Media Video plays only inside the player dialog — nothing is fetched until the user opens it; res.sendFile → native Accept-Ranges/206 support → browser pulls only the segments it needs on seek/play

Data Model

See Models#Video and Models#VideoEntry for field details, Database#Relationships for the relations.

videos (id, title, description, filename, original_name, mime_type, size, ...)
  └── video_entries (video_id, entry_id) ── entries

API

Method Path Description
GET /discovery-videos?page=&limit= Paginated list (includes linked entries)
POST /discovery-videos Multipart upload: videos[] (≤ 10), description, entryIds (JSON array)
PUT /discovery-videos/:id Update title / description / entry links
DELETE /discovery-videos/:id Delete record + files from disk
GET /discovery-videos/:id/stream Video stream with HTTP Range support
GET /discovery-videos/:id/thumbnail Thumbnail image — generated on demand when missing (served in the same response)

Auth: stream URLs append ?token=<authToken> (the <video> tag cannot send Authorization headers). See API Reference.

Allowed extensions: mp4, webm, mov, m4v, mkv, avi. Note: mkv/avi may not play in browsers — mp4 (H.264) is recommended.


Important Files

Backend

  • backend/models/Video.js — video record model
  • backend/models/VideoEntry.js — junction model (video ↔ entry)
  • backend/controllers/videoController.js — list/upload/update/delete/stream/thumbnail
  • backend/routes/video.routes.js — mounted at /api/v1/discovery-videos
  • backend/services/mutlerStorageLocations.js — videosUpload multer config
  • backend/services/videoThumbnailService.js — on-demand ffmpeg thumbnail generation (deduped, concurrency-limited)

Frontend

  • react_frontend/src/pages/DiscoveryVideosPage.tsx — page (grid + infinite scroll + player state)
  • react_frontend/src/components/discovery-videos/VideoCard.tsx — thumbnail card with play overlay
  • react_frontend/src/components/discovery-videos/VideoPlayerDialog.tsx — playback dialog with ↑/↓ navigation
  • react_frontend/src/components/discovery-videos/AddVideoDialog.tsx — create/edit dialog
  • react_frontend/src/components/discovery-videos/VideoDropzone.tsx — native drag & drop
  • react_frontend/src/components/discovery-videos/EntryMultiSelect.tsx — library entry picker (reads from Stores)
  • react_frontend/src/api/discoveryVideos.ts — API module
  • react_frontend/src/hooks/useDiscoveryVideos.ts — query/mutations

Known Limitations

  • Thumbnails are generated on demand (first request, ffmpeg frame at 1s) — the first load of a thumbnail takes a moment; ffmpeg-static must ship in the packaged build (see backend/pnpm-workspace.yaml build approval)
  • No transcoding — unsupported codecs will fail in the browser player
  • No per-video watch state ("already watched") yet
  • Multi-file uploads share one description + entry set (editable per video afterwards)

See Also