Eerste commit voor rename-mvp
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from app.services.tvdb_auth_service import TvdbAuthService
|
||||
from app.services.tvdb_client import TvdbClient
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/auth-status")
|
||||
def auth_status():
|
||||
service = TvdbAuthService()
|
||||
return service.auth_status()
|
||||
|
||||
|
||||
@router.post("/login")
|
||||
def force_login():
|
||||
service = TvdbAuthService()
|
||||
try:
|
||||
state = service.login_and_store_token()
|
||||
return {
|
||||
"status": "ok",
|
||||
"issued_at": state["issued_at"],
|
||||
"expires_at": state["expires_at"],
|
||||
"renew_after": state["renew_after"],
|
||||
}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/search")
|
||||
def search_series(q: str = Query(..., min_length=1)):
|
||||
"""
|
||||
Eenvoudige smoke test richting TVDB.
|
||||
Deze proxy gebruikt de backend token flow en filtert series uit het resultaat.
|
||||
"""
|
||||
client = TvdbClient()
|
||||
try:
|
||||
# In TVDB v4 wordt search via de API ondersteund; deze proxy is bewust dun.
|
||||
payload = client.get("/search", params={"query": q, "type": "series"})
|
||||
items = payload.get("data", [])
|
||||
normalized = []
|
||||
|
||||
for item in items:
|
||||
name = item.get("name") or item.get("seriesName") or item.get("slug")
|
||||
year = item.get("year")
|
||||
normalized.append(
|
||||
{
|
||||
"id": item.get("tvdb_id") or item.get("id"),
|
||||
"name": name,
|
||||
"year": year,
|
||||
"display_name": f"{name} ({year})" if name and year else name,
|
||||
"raw": item,
|
||||
}
|
||||
)
|
||||
|
||||
return {"items": normalized}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user