Remove unused fallback cover handling
This commit is contained in:
parent
5f0c7737fe
commit
a952c36ab7
|
@ -732,29 +732,27 @@ def delete_book(book, calibrepath, book_format):
|
||||||
return delete_book_file(book, calibrepath, book_format)
|
return delete_book_file(book, calibrepath, book_format)
|
||||||
|
|
||||||
|
|
||||||
def get_cover_on_failure(use_generic_cover):
|
def get_cover_on_failure():
|
||||||
if use_generic_cover:
|
try:
|
||||||
try:
|
return send_from_directory(_STATIC_DIR, "generic_cover.jpg")
|
||||||
return send_from_directory(_STATIC_DIR, "generic_cover.jpg")
|
except PermissionError:
|
||||||
except PermissionError:
|
log.error("No permission to access generic_cover.jpg file.")
|
||||||
log.error("No permission to access generic_cover.jpg file.")
|
abort(403)
|
||||||
abort(403)
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
|
|
||||||
def get_book_cover(book_id, resolution=None):
|
def get_book_cover(book_id, resolution=None):
|
||||||
book = calibre_db.get_filtered_book(book_id, allow_show_archived=True)
|
book = calibre_db.get_filtered_book(book_id, allow_show_archived=True)
|
||||||
return get_book_cover_internal(book, use_generic_cover_on_failure=True, resolution=resolution)
|
return get_book_cover_internal(book, resolution=resolution)
|
||||||
|
|
||||||
|
|
||||||
def get_book_cover_with_uuid(book_uuid, resolution=None, none_on_missing=False):
|
def get_book_cover_with_uuid(book_uuid, resolution=None):
|
||||||
book = calibre_db.get_book_by_uuid(book_uuid)
|
book = calibre_db.get_book_by_uuid(book_uuid)
|
||||||
if not book and none_on_missing:
|
if not book:
|
||||||
return # allows kobo.HandleCoverImageRequest to proxy request
|
return # allows kobo.HandleCoverImageRequest to proxy request
|
||||||
return get_book_cover_internal(book, use_generic_cover_on_failure=False, resolution=resolution)
|
return get_book_cover_internal(book, resolution=resolution)
|
||||||
|
|
||||||
|
|
||||||
def get_book_cover_internal(book, use_generic_cover_on_failure, resolution=None):
|
def get_book_cover_internal(book, resolution=None):
|
||||||
if book and book.has_cover:
|
if book and book.has_cover:
|
||||||
|
|
||||||
# Send the book cover thumbnail if it exists in cache
|
# Send the book cover thumbnail if it exists in cache
|
||||||
|
@ -770,16 +768,16 @@ def get_book_cover_internal(book, use_generic_cover_on_failure, resolution=None)
|
||||||
if config.config_use_google_drive:
|
if config.config_use_google_drive:
|
||||||
try:
|
try:
|
||||||
if not gd.is_gdrive_ready():
|
if not gd.is_gdrive_ready():
|
||||||
return get_cover_on_failure(use_generic_cover_on_failure)
|
return get_cover_on_failure()
|
||||||
path = gd.get_cover_via_gdrive(book.path)
|
path = gd.get_cover_via_gdrive(book.path)
|
||||||
if path:
|
if path:
|
||||||
return redirect(path)
|
return redirect(path)
|
||||||
else:
|
else:
|
||||||
log.error('{}/cover.jpg not found on Google Drive'.format(book.path))
|
log.error('{}/cover.jpg not found on Google Drive'.format(book.path))
|
||||||
return get_cover_on_failure(use_generic_cover_on_failure)
|
return get_cover_on_failure()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
log.error_or_exception(ex)
|
log.error_or_exception(ex)
|
||||||
return get_cover_on_failure(use_generic_cover_on_failure)
|
return get_cover_on_failure()
|
||||||
|
|
||||||
# Send the book cover from the Calibre directory
|
# Send the book cover from the Calibre directory
|
||||||
else:
|
else:
|
||||||
|
@ -787,9 +785,9 @@ def get_book_cover_internal(book, use_generic_cover_on_failure, resolution=None)
|
||||||
if os.path.isfile(os.path.join(cover_file_path, "cover.jpg")):
|
if os.path.isfile(os.path.join(cover_file_path, "cover.jpg")):
|
||||||
return send_from_directory(cover_file_path, "cover.jpg")
|
return send_from_directory(cover_file_path, "cover.jpg")
|
||||||
else:
|
else:
|
||||||
return get_cover_on_failure(use_generic_cover_on_failure)
|
return get_cover_on_failure()
|
||||||
else:
|
else:
|
||||||
return get_cover_on_failure(use_generic_cover_on_failure)
|
return get_cover_on_failure()
|
||||||
|
|
||||||
|
|
||||||
def get_book_cover_thumbnail(book, resolution):
|
def get_book_cover_thumbnail(book, resolution):
|
||||||
|
@ -812,7 +810,7 @@ def get_series_thumbnail_on_failure(series_id, resolution):
|
||||||
.filter(db.Books.has_cover == 1) \
|
.filter(db.Books.has_cover == 1) \
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
return get_book_cover_internal(book, use_generic_cover_on_failure=True, resolution=resolution)
|
return get_book_cover_internal(book, resolution=resolution)
|
||||||
|
|
||||||
|
|
||||||
def get_series_cover_thumbnail(series_id, resolution=None):
|
def get_series_cover_thumbnail(series_id, resolution=None):
|
||||||
|
|
32
cps/kobo.py
32
cps/kobo.py
|
@ -930,23 +930,21 @@ def get_current_bookmark_response(current_bookmark):
|
||||||
@kobo.route("/<book_uuid>/<width>/<height>/<Quality>/<isGreyscale>/image.jpg")
|
@kobo.route("/<book_uuid>/<width>/<height>/<Quality>/<isGreyscale>/image.jpg")
|
||||||
@requires_kobo_auth
|
@requires_kobo_auth
|
||||||
def HandleCoverImageRequest(book_uuid, width, height, Quality, isGreyscale):
|
def HandleCoverImageRequest(book_uuid, width, height, Quality, isGreyscale):
|
||||||
book_cover = helper.get_book_cover_with_uuid(
|
book_cover = helper.get_book_cover_with_uuid(book_uuid, resolution=COVER_THUMBNAIL_SMALL)
|
||||||
book_uuid,
|
if book_cover:
|
||||||
resolution=COVER_THUMBNAIL_SMALL,
|
log.debug("Serving local cover image of book %s" % book_uuid)
|
||||||
none_on_missing=config.config_kobo_proxy)
|
return book_cover
|
||||||
if not book_cover:
|
|
||||||
if config.config_kobo_proxy:
|
if not config.config_kobo_proxy:
|
||||||
log.debug("Cover for unknown book: %s proxied to kobo" % book_uuid)
|
log.debug("Returning 404 for cover image of unknown book %s" % book_uuid)
|
||||||
return redirect(KOBO_IMAGEHOST_URL +
|
# additional proxy request make no sense, -> direct return
|
||||||
"/{book_uuid}/{width}/{height}/false/image.jpg".format(book_uuid=book_uuid,
|
return abort(404)
|
||||||
width=width,
|
|
||||||
height=height), 307)
|
log.debug("Redirecting request for cover image of unknown book %s to Kobo" % book_uuid)
|
||||||
else:
|
return redirect(KOBO_IMAGEHOST_URL +
|
||||||
log.debug("Cover for unknown book: %s requested" % book_uuid)
|
"/{book_uuid}/{width}/{height}/false/image.jpg".format(book_uuid=book_uuid,
|
||||||
# additional proxy request make no sense, -> direct return
|
width=width,
|
||||||
return abort(404)
|
height=height), 307)
|
||||||
log.debug("Cover request received for book %s" % book_uuid)
|
|
||||||
return book_cover
|
|
||||||
|
|
||||||
|
|
||||||
@kobo.route("")
|
@kobo.route("")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user