The browse scope is a pure DB query with no request state, but it lived in routes/plex/_shared.py. E24's Home surface needs the same scope from a domain package, and a domain package importing from routes/ inverts the one-way dependency CLAUDE.md draws. Moved to app/plex/query.py and renamed to content_libs (public — it is a domain helper now). Swept all five call sites and both tests in one go rather than leaving a re-export shim: the canonical-patterns table already names the routes.admin re-export as the anti-pattern.
24 lines
677 B
Python
24 lines
677 B
Python
"""Shared helpers, serializers and constants for the plex route package."""
|
|
|
|
import logging
|
|
|
|
from fastapi import HTTPException
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.models import PlexItem
|
|
from app.plex.lookups import by_rating_key
|
|
|
|
log = logging.getLogger("siftlode.plex")
|
|
|
|
|
|
def item_or_404(db: Session, rating_key: str) -> PlexItem:
|
|
it = by_rating_key(db, PlexItem, rating_key)
|
|
if it is None:
|
|
raise HTTPException(status_code=404, detail="Unknown Plex item")
|
|
return it
|
|
|
|
|
|
def _norm_lang(lang: str | None) -> str:
|
|
"""The overlay has an EN base + an optional HU twin; anything other than `hu` serves EN."""
|
|
return "hu" if lang == "hu" else "en"
|