add video backend server, fix styling and more #54

Merged
quoije merged 131 commits from 2026-video.backend into prod 2025-12-22 05:42:04 -05:00
2 changed files with 29 additions and 1 deletions
Showing only changes of commit 53eb7faf06 - Show all commits
+29 -1
View File
@@ -5,6 +5,7 @@ from datetime import datetime, timezone
from pathlib import Path
from typing import Generator, Optional, Tuple
from urllib.parse import quote
from urllib.parse import urlparse
import jwt
from bson import ObjectId
@@ -28,6 +29,26 @@ def _mongo_uri() -> str:
# Read env at runtime (important on Windows/uvicorn worker reloads).
return _env_str("MONGO_URI")
def _mongo_db_name() -> str:
# Prefer explicit env var, otherwise try to parse from URI path.
explicit = _env_str("MONGO_DB_NAME")
if explicit:
return explicit
uri = _mongo_uri()
if not uri:
return ""
try:
parsed = urlparse(uri)
# Path is like "/dbname"
db = (parsed.path or "").lstrip("/")
# Strip any extra segments just in case
db = db.split("/")[0].strip()
return db
except Exception:
return ""
def _video_files_dir() -> Path:
# Read env at runtime (important on Windows/uvicorn worker reloads).
@@ -191,7 +212,13 @@ def stream_video(
raise HTTPException(status_code=400, detail="Invalid movie id")
with _mongo_client() as client:
db = client.get_default_database()
db_name = _mongo_db_name()
if not db_name:
raise HTTPException(
status_code=500,
detail="Mongo DB name not configured. Add it to MONGO_URI (…/dbname) or set MONGO_DB_NAME.",
)
db = client[db_name]
movie = db["movies"].find_one({"_id": oid}, {"video_file": 1})
video_file = (movie or {}).get("video_file") or ""
@@ -259,5 +286,6 @@ def healthz():
"ok": True,
"time": datetime.now(timezone.utc).isoformat(),
"video_files_dir": str(_video_files_dir()),
"mongo_db_name": _mongo_db_name() or None,
}