File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"""Core book CRUD and file-serving endpoint handlers."""
2+ import glob
23import hashlib
34import os
45from typing import Optional
89
910from ...auth import CurrentUser , get_current_user , require_gm_or_admin
1011from ...config import _PAGE_CACHE_HEADERS , SessionLocal , THUMB_DIR
11- from ... indexer import slugify
12+
1213from ...models import Book , GameSystem
1314from ._helpers import _allow_explicit
1415from ._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 ()
You can’t perform that action at this time.
0 commit comments