Skip to content

Feature: Add video download support (#202)#497

Merged
filthyrake merged 2 commits intodevfrom
feature/202-video-downloads
Jan 4, 2026
Merged

Feature: Add video download support (#202)#497
filthyrake merged 2 commits intodevfrom
feature/202-video-downloads

Conversation

@filthyrake
Copy link
Copy Markdown
Owner

Summary

Implements video download functionality for the VLog platform (Issue #202).

  • Add configuration and API endpoints for video downloads
  • Downloads are disabled by default for security (as requested)
  • Original file downloads only; transcoded quality downloads planned for future release
  • Includes rate limiting and concurrency controls

Configuration Options

Setting Default Description
VLOG_DOWNLOADS_ENABLED false Master switch - must be explicitly enabled
VLOG_DOWNLOADS_REQUIRE_AUTH true Require authentication for downloads
VLOG_DOWNLOADS_ALLOW_ORIGINAL false Allow original file downloads
VLOG_DOWNLOADS_ALLOW_TRANSCODED true Allow transcoded quality downloads (future)
VLOG_DOWNLOADS_RATE_LIMIT_PER_HOUR 10 Rate limit per IP
VLOG_DOWNLOADS_MAX_CONCURRENT 2 Max concurrent downloads per IP

Changes

  • config.py: Add download configuration with secure defaults
  • api/settings_service.py: Add database-backed settings for admin UI
  • api/public.py: Add /api/config/downloads and /api/videos/{slug}/download/original endpoints
  • web/public/watch.html: Add download button (conditionally shown when enabled)
  • web/public/static/js/pages/watch.js: Add download config loading
  • .env.example: Document all new configuration options

Test Plan

  • Verify downloads are disabled by default (no download button visible)
  • Enable VLOG_DOWNLOADS_ENABLED=true and verify config endpoint returns enabled
  • Enable VLOG_DOWNLOADS_ALLOW_ORIGINAL=true and verify download button appears
  • Test download of original file works correctly
  • Verify rate limiting works when configured
  • Verify 403 response when downloads are disabled

Future Work

  • Transcoded quality downloads (generate MP4 from HLS/DASH segments)
  • Authentication integration for require_auth setting
  • Download analytics tracking

Closes #202

🤖 Generated with Claude Code

filthyrake and others added 2 commits January 3, 2026 16:07
Add configuration and API endpoints for video download functionality.
Downloads are disabled by default for security, requiring explicit
opt-in via environment variables or admin settings.

Configuration options:
- VLOG_DOWNLOADS_ENABLED: Master switch (default: false)
- VLOG_DOWNLOADS_REQUIRE_AUTH: Auth requirement (default: true)
- VLOG_DOWNLOADS_ALLOW_ORIGINAL: Original file downloads (default: false)
- VLOG_DOWNLOADS_ALLOW_TRANSCODED: Transcoded quality downloads (default: true)
- VLOG_DOWNLOADS_RATE_LIMIT_PER_HOUR: Rate limiting (default: 10/hour)
- VLOG_DOWNLOADS_MAX_CONCURRENT: Concurrency limit (default: 2)

Changes:
- Add download configuration to config.py with secure defaults
- Add download settings to settings_service.py for database-backed config
- Add /api/config/downloads endpoint for UI configuration
- Add /api/videos/{slug}/download/original endpoint for original files
- Add download button to watch.html (conditionally shown when enabled)
- Update .env.example with documentation for all new settings

Note: Transcoded quality downloads (MP4 from HLS/DASH segments) are
planned for a future release. Currently only original file downloads
are supported.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Critical fixes from security, reliability, and performance reviews:

Security (Bruce):
- Remove unimplemented require_auth setting to avoid false security
- Add RFC 5987 filename encoding to prevent header injection
- Validate file extension is in allowed list before serving
- Add proper media type detection based on file extension

Reliability (Margo):
- Add asyncio.Lock to prevent cache thundering herd on expiry
- Implement concurrent download tracking with proper slot management
- Add comprehensive filesystem error handling (OSError, permissions)
- Add file validation (empty files, size limits, readable check)
- Add storage availability dependency check
- Reduce TOCTOU window with final validation before serving
- Change logging from DEBUG to WARNING for operational issues

Performance (Brendan):
- Implement max_concurrent enforcement (was configured but not used)
- Add 100GB file size sanity check
- Document that rate limit requires restart to change

Code Quality:
- Add comprehensive test suite (18 tests covering all scenarios)
- Improve filename sanitization (length limit, space handling)
- Add proper docstrings with raised exceptions documented

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@filthyrake
Copy link
Copy Markdown
Owner Author

Code Review Fixes Applied

All issues identified by the specialized review agents have been addressed:

Critical Fixes

Issue Resolution
Authentication not implemented Removed require_auth setting entirely to avoid false security
Concurrent download limit not enforced Implemented _acquire_download_slot() / _release_download_slot() with asyncio.Lock
Cache race condition Added double-checked locking pattern with asyncio.Lock
TOCTOU race condition Added final validation immediately before FileResponse

Security Fixes

  • RFC 5987 filename encoding for Content-Disposition header
  • Extension validation against whitelist before serving
  • Proper media type detection from file extension
  • 100GB file size sanity check

Reliability Fixes

  • Comprehensive OSError/PermissionError handling in file lookup
  • Empty file detection
  • File readability check before serving
  • Storage availability dependency
  • Improved logging (DEBUG → WARNING for operational issues)

Performance Fixes

  • Concurrent download tracking now enforced (was advertised but unused)
  • Documented that rate limit requires restart to change

Tests Added

  • 18 comprehensive tests covering all scenarios
  • Tests for concurrent limits, file validation, cache locking, MIME types, filename generation

All 18 tests pass. Ready for re-review! 🚀

@filthyrake filthyrake merged commit e30ef33 into dev Jan 4, 2026
4 checks passed
@filthyrake filthyrake deleted the feature/202-video-downloads branch January 4, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Video download support

1 participant