Added thumbnail urls to book cover srcsets with cache busting ids
This commit is contained in:
@@ -533,6 +533,21 @@ def delete_book(book, calibrepath, book_format):
|
||||
return delete_book_file(book, calibrepath, book_format)
|
||||
|
||||
|
||||
def get_thumbnails_for_books(books):
|
||||
books_with_covers = list(filter(lambda b: b.has_cover, books))
|
||||
book_ids = list(map(lambda b: b.id, books_with_covers))
|
||||
return ub.session\
|
||||
.query(ub.Thumbnail)\
|
||||
.filter(ub.Thumbnail.book_id.in_(book_ids))\
|
||||
.filter(ub.Thumbnail.expiration > datetime.utcnow())\
|
||||
.all()
|
||||
|
||||
|
||||
def get_thumbnails_for_book_series(series):
|
||||
books = list(map(lambda s: s[0], series))
|
||||
return get_thumbnails_for_books(books)
|
||||
|
||||
|
||||
def get_cover_on_failure(use_generic_cover):
|
||||
if use_generic_cover:
|
||||
return send_from_directory(_STATIC_DIR, "generic_cover.jpg")
|
||||
@@ -558,6 +573,29 @@ def get_cached_book_cover(cache_id):
|
||||
return get_book_cover_internal(book, use_generic_cover_on_failure=True, resolution=resolution)
|
||||
|
||||
|
||||
def get_cached_book_cover_thumbnail(cache_id):
|
||||
parts = cache_id.split('_')
|
||||
thumbnail_uuid = parts[0] if len(parts) else None
|
||||
thumbnail = None
|
||||
if thumbnail_uuid:
|
||||
thumbnail = ub.session\
|
||||
.query(ub.Thumbnail)\
|
||||
.filter(ub.Thumbnail.uuid == thumbnail_uuid)\
|
||||
.first()
|
||||
|
||||
if thumbnail and thumbnail.expiration > datetime.utcnow():
|
||||
cache = fs.FileSystem()
|
||||
if cache.get_cache_file_path(thumbnail.filename, fs.CACHE_TYPE_THUMBNAILS):
|
||||
return send_from_directory(cache.get_cache_dir(fs.CACHE_TYPE_THUMBNAILS), thumbnail.filename)
|
||||
|
||||
elif thumbnail:
|
||||
book = calibre_db.get_book(thumbnail.book_id)
|
||||
return get_book_cover_internal(book, use_generic_cover_on_failure=True)
|
||||
|
||||
else:
|
||||
return get_cover_on_failure(True)
|
||||
|
||||
|
||||
def get_book_cover_internal(book, use_generic_cover_on_failure, resolution=None):
|
||||
if book and book.has_cover:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user