Skip to content

Commit 33bea08

Browse files
committed
Triggering cover updates by adding version to coverImageId
This way when ChangedProductMetadata is sent, the coverImageId will be updated, and will trigger a redownload of the cover Moving thumbnail generatedAt fetch to query in metadata function
1 parent 9a5d241 commit 33bea08

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

cps/kobo.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from time import gmtime, strftime
2626
import json
2727
from urllib.parse import unquote
28+
import uuid
2829

2930
from flask import (
3031
Blueprint,
@@ -512,10 +513,22 @@ def get_metadata(book):
512513
log.error(e)
513514

514515
book_uuid = book.uuid
516+
517+
thumbnail_generated_at = (
518+
calibre_db.session
519+
.query(ub.Thumbnail.generated_at)
520+
.filter(ub.Thumbnail.entity_id == book.id)
521+
.order_by(ub.Thumbnail.id)
522+
.limit(1)
523+
).scalar()
524+
525+
#turn thumbnail generated_at timestamp into an epoch for use as the version
526+
version_str = f"{thumbnail_generated_at.timestamp():.0f}"
527+
515528
metadata = {
516529
"Categories": ["00000000-0000-0000-0000-000000000001", ],
517530
# "Contributors": get_author(book),
518-
"CoverImageId": book_uuid,
531+
"CoverImageId": book_uuid+"/"+version_str,
519532
"CrossRevisionId": book_uuid,
520533
"CurrentDisplayPrice": {"CurrencyCode": "USD", "TotalAmount": 0},
521534
"CurrentLoveDisplayPrice": {"TotalAmount": 0},
@@ -954,10 +967,12 @@ def get_current_bookmark_response(current_bookmark):
954967
return resp
955968

956969

957-
@kobo.route("/<book_uuid>/<width>/<height>/<isGreyscale>/image.jpg", defaults={'Quality': ""})
958-
@kobo.route("/<book_uuid>/<width>/<height>/<Quality>/<isGreyscale>/image.jpg")
970+
@kobo.route("/<book_uuid>/<width>/<height>/<isGreyscale>/image.jpg", defaults={'Quality': "", 'version': ""})
971+
@kobo.route("/<book_uuid>/<width>/<height>/<Quality>/<isGreyscale>/image.jpg", defaults={'version': ""})
972+
@kobo.route("/<book_uuid>/<version>/<width>/<height>/<isGreyscale>/image.jpg", defaults={'Quality': ""})
973+
@kobo.route("/<book_uuid>/<version>/<width>/<height>/<Quality>/<isGreyscale>/image.jpg")
959974
@requires_kobo_auth
960-
def HandleCoverImageRequest(book_uuid, width, height, Quality, isGreyscale):
975+
def HandleCoverImageRequest(book_uuid, version, width, height, Quality, isGreyscale):
961976
try:
962977
if int(height) > 1000:
963978
resolution = COVER_THUMBNAIL_LARGE

0 commit comments

Comments
 (0)