--- title: Discovery Videos tags: - feature - frontend - backend - videos aliases: - 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|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()` + `` with `DiscoveryVideosSkeleton` | | Data | Paginated API + `useInfiniteQuery` + IntersectionObserver sentinel (`rootMargin: "400px"`) — only metadata travels, never video bytes | | Thumbnails | `` 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=` (the `