Skip to content

Commit 00fbaed

Browse files
authored
Fix: Fix thumbnail 404 after book rename (#85)
1 parent d1ed9e8 commit 00fbaed

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

backend/routers/books/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Core book CRUD and file-serving endpoint handlers."""
2+
import glob
23
import hashlib
34
import os
45
from typing import Optional
@@ -8,7 +9,7 @@
89

910
from ...auth import CurrentUser, get_current_user, require_gm_or_admin
1011
from ...config import _PAGE_CACHE_HEADERS, SessionLocal, THUMB_DIR
11-
from ...indexer import slugify
12+
1213
from ...models import Book, GameSystem
1314
from ._helpers import _allow_explicit
1415
from ._schemas import BookUpdate
@@ -139,11 +140,10 @@ def serve_book_thumbnail(book_id: str):
139140
book = db.query(Book).filter_by(id=book_id).first()
140141
if not book:
141142
raise HTTPException(404)
142-
slug = slugify(book.title)
143143
fhash = hashlib.md5(book.filepath.encode()).hexdigest()[:8]
144-
thumb_path = os.path.join(THUMB_DIR, "books", f"{slug}_{fhash}.webp")
145-
if os.path.exists(thumb_path):
146-
return FileResponse(thumb_path, media_type="image/webp", headers=_PAGE_CACHE_HEADERS)
144+
matches = glob.glob(os.path.join(THUMB_DIR, "books", f"*_{fhash}.webp"))
145+
if matches:
146+
return FileResponse(matches[0], media_type="image/webp", headers=_PAGE_CACHE_HEADERS)
147147
raise HTTPException(404, "No thumbnail available")
148148
finally:
149149
db.close()

0 commit comments

Comments
 (0)