feat(plex): restore Collections filter as a cross-library union picker
The searchable Collections picker was dropped from the sidebar when browsing went unified (movies+shows across libraries) because collections are per-library and there's no single selected library. Bring it back library-agnostic: GET /api/plex/collections `library` is now optional — without it the endpoint unions collections across all enabled libraries (with it, the old single-library path the collection editor uses). The sidebar re-adds the searchable list (chip when one is active). Its query key is ["plex-collections","union",<search>] so a search term equal to a library plex_key can't collide with the editor's ["plex-collections",<key>], while the shared prefix keeps editor invalidation refreshing the picker.
This commit is contained in:
parent
b3af04a997
commit
5759deac20
3 changed files with 72 additions and 16 deletions
|
|
@ -748,16 +748,25 @@ def _collection_card(c: PlexCollection) -> dict:
|
|||
|
||||
@router.get("/collections")
|
||||
def collections(
|
||||
library: str,
|
||||
library: str | None = None,
|
||||
q: str | None = None,
|
||||
user: User = Depends(current_user),
|
||||
db: Session = Depends(get_db),
|
||||
) -> dict:
|
||||
"""The library's mirrored collections as cards (most-populated first). Optional name filter `q`."""
|
||||
lib = db.query(PlexLibrary).filter_by(plex_key=str(library)).first()
|
||||
if lib is None:
|
||||
return {"collections": []}
|
||||
query = db.query(PlexCollection).filter(PlexCollection.library_id == lib.id)
|
||||
"""Mirrored collections as cards (most-populated first), optionally name-filtered by `q`. With a
|
||||
`library` plex_key → that one library's collections (used by the collection editor). WITHOUT one →
|
||||
the UNION across all enabled libraries (the unified-scope sidebar picker, which has no single
|
||||
library selected)."""
|
||||
if library is not None:
|
||||
lib = db.query(PlexLibrary).filter_by(plex_key=str(library)).first()
|
||||
if lib is None:
|
||||
return {"collections": []}
|
||||
query = db.query(PlexCollection).filter(PlexCollection.library_id == lib.id)
|
||||
else:
|
||||
enabled_ids = [lb.id for lb in db.query(PlexLibrary.id).filter_by(enabled=True)]
|
||||
if not enabled_ids:
|
||||
return {"collections": []}
|
||||
query = db.query(PlexCollection).filter(PlexCollection.library_id.in_(enabled_ids))
|
||||
term = (q or "").strip()
|
||||
if term:
|
||||
query = query.filter(PlexCollection.title.ilike(f"%{_like_escape(term)}%"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue