Fallback to TMDB when artwork cache fails (build 271261524)
This commit is contained in:
@@ -1 +1 @@
|
|||||||
271261335
|
271261524
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from fastapi import APIRouter, HTTPException, Response
|
from fastapi import APIRouter, HTTPException, Response
|
||||||
from fastapi.responses import FileResponse, RedirectResponse
|
from fastapi.responses import FileResponse, RedirectResponse
|
||||||
@@ -12,6 +13,7 @@ router = APIRouter(prefix="/images", tags=["images"])
|
|||||||
|
|
||||||
_TMDB_BASE = "https://image.tmdb.org/t/p"
|
_TMDB_BASE = "https://image.tmdb.org/t/p"
|
||||||
_ALLOWED_SIZES = {"w92", "w154", "w185", "w342", "w500", "w780", "original"}
|
_ALLOWED_SIZES = {"w92", "w154", "w185", "w342", "w500", "w780", "original"}
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _safe_filename(path: str) -> str:
|
def _safe_filename(path: str) -> str:
|
||||||
@@ -91,6 +93,8 @@ async def tmdb_image(path: str, size: str = "w342"):
|
|||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
media_type = mimetypes.guess_type(file_path)[0] or "image/jpeg"
|
media_type = mimetypes.guess_type(file_path)[0] or "image/jpeg"
|
||||||
return FileResponse(file_path, media_type=media_type, headers=headers)
|
return FileResponse(file_path, media_type=media_type, headers=headers)
|
||||||
raise HTTPException(status_code=502, detail="Image cache failed")
|
logger.warning("TMDB cache miss after fetch: path=%s size=%s", path, size)
|
||||||
except httpx.HTTPError as exc:
|
except (httpx.HTTPError, OSError) as exc:
|
||||||
raise HTTPException(status_code=502, detail=f"Image fetch failed: {exc}") from exc
|
logger.warning("TMDB cache failed: path=%s size=%s error=%s", path, size, exc)
|
||||||
|
|
||||||
|
return RedirectResponse(url=url)
|
||||||
|
|||||||
Reference in New Issue
Block a user