Files
streamrip-ui/backend/app/api/search.py
T
loki 99cfda2b08
CI / backend-tests (push) Successful in 8s
Docker images / backend (push) Successful in 7s
Docker images / frontend (push) Successful in 22s
CI / docker (push) Successful in 3s
feat: mehr-laden paging (suche + entdecken, totals, fallback-skip)
2026-10-04 16:39:16 +02:00

30 lines
1007 B
Python

from typing import Literal
from fastapi import APIRouter, HTTPException, Query
from app.services import streamrip_service
router = APIRouter(prefix="/api/search", tags=["search"])
MediaType = Literal["track", "album", "artist", "playlist", "podcast"]
@router.get("")
async def search(
type: MediaType = Query(...),
q: str = Query(..., min_length=0, max_length=200),
limit: int = Query(20, ge=1, le=100),
index: int = Query(0, ge=0, le=1000),
):
query = q.strip()
if not query:
raise HTTPException(status_code=400, detail="Empty query")
try:
if type == "podcast":
results, total = await streamrip_service.search_podcasts(query, limit, index)
else:
results, total = await streamrip_service.search_deezer(type, query, limit, index)
except Exception as e:
raise HTTPException(status_code=502, detail=f"Search failed: {e}")
return {"results": results, "type": type, "query": query, "total": total, "index": index}