mirror of
https://github.com/janeczku/calibre-web
synced 2025-09-11 15:26:00 +00:00
Revert "feat: resize images directly at cover endpoint"
This reverts commit ba383643f5
.
This commit is contained in:
@@ -30,12 +30,10 @@ import requests
|
|||||||
import unidecode
|
import unidecode
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from flask import send_from_directory, make_response, abort, url_for, Response, redirect
|
from flask import send_from_directory, make_response, abort, url_for, Response
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
from flask_babel import lazy_gettext as N_
|
from flask_babel import lazy_gettext as N_
|
||||||
from flask_babel import get_locale
|
from flask_babel import get_locale
|
||||||
from flask_image_resizer import resized_img_src
|
|
||||||
|
|
||||||
from .cw_login import current_user
|
from .cw_login import current_user
|
||||||
from sqlalchemy.sql.expression import true, false, and_, or_, text, func
|
from sqlalchemy.sql.expression import true, false, and_, or_, text, func
|
||||||
from sqlalchemy.exc import InvalidRequestError, OperationalError
|
from sqlalchemy.exc import InvalidRequestError, OperationalError
|
||||||
@@ -751,8 +749,6 @@ def get_book_cover_with_uuid(book_uuid, resolution=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_book_cover_internal(book, resolution=None):
|
def get_book_cover_internal(book, resolution=None):
|
||||||
"""returns an optimized version of the cover, unless using google drive"""
|
|
||||||
|
|
||||||
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
|
||||||
@@ -761,13 +757,8 @@ def get_book_cover_internal(book, resolution=None):
|
|||||||
if thumbnail:
|
if thumbnail:
|
||||||
cache = fs.FileSystem()
|
cache = fs.FileSystem()
|
||||||
if cache.get_cache_file_exists(thumbnail.filename, CACHE_TYPE_THUMBNAILS):
|
if cache.get_cache_file_exists(thumbnail.filename, CACHE_TYPE_THUMBNAILS):
|
||||||
return redirect(resized_img_src(
|
return send_from_directory(cache.get_cache_file_dir(thumbnail.filename, CACHE_TYPE_THUMBNAILS),
|
||||||
os.path.join(
|
thumbnail.filename)
|
||||||
cache.get_cache_file_dir(thumbnail.filename, CACHE_TYPE_THUMBNAILS),
|
|
||||||
thumbnail.filename
|
|
||||||
),
|
|
||||||
format="webp"
|
|
||||||
))
|
|
||||||
|
|
||||||
# Send the book cover from Google Drive if configured
|
# Send the book cover from Google Drive if configured
|
||||||
if config.config_use_google_drive:
|
if config.config_use_google_drive:
|
||||||
@@ -786,9 +777,9 @@ def get_book_cover_internal(book, resolution=None):
|
|||||||
|
|
||||||
# Send the book cover from the Calibre directory
|
# Send the book cover from the Calibre directory
|
||||||
else:
|
else:
|
||||||
cover_file_path = os.path.join(config.get_book_path(), book.path, "cover.jpg")
|
cover_file_path = os.path.join(config.get_book_path(), book.path)
|
||||||
if os.path.isfile(cover_file_path):
|
if os.path.isfile(os.path.join(cover_file_path, "cover.jpg")):
|
||||||
return redirect(resized_img_src(cover_file_path, format="webp"))
|
return send_from_directory(cover_file_path, "cover.jpg")
|
||||||
else:
|
else:
|
||||||
return get_cover_on_failure()
|
return get_cover_on_failure()
|
||||||
else:
|
else:
|
||||||
@@ -829,13 +820,8 @@ def get_series_cover_internal(series_id, resolution=None):
|
|||||||
if thumbnail:
|
if thumbnail:
|
||||||
cache = fs.FileSystem()
|
cache = fs.FileSystem()
|
||||||
if cache.get_cache_file_exists(thumbnail.filename, CACHE_TYPE_THUMBNAILS):
|
if cache.get_cache_file_exists(thumbnail.filename, CACHE_TYPE_THUMBNAILS):
|
||||||
return redirect(resized_img_src(
|
return send_from_directory(cache.get_cache_file_dir(thumbnail.filename, CACHE_TYPE_THUMBNAILS),
|
||||||
os.path.join(
|
thumbnail.filename)
|
||||||
cache.get_cache_file_dir(thumbnail.filename, CACHE_TYPE_THUMBNAILS),
|
|
||||||
thumbnail.filename
|
|
||||||
),
|
|
||||||
format="webp"
|
|
||||||
))
|
|
||||||
|
|
||||||
return get_series_thumbnail_on_failure(series_id, resolution)
|
return get_series_thumbnail_on_failure(series_id, resolution)
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
{% set srcset = book|get_cover_srcset %}
|
{% set srcset = book|get_cover_srcset %}
|
||||||
<img
|
<img
|
||||||
srcset="{{ srcset }}"
|
srcset="{{ srcset }}"
|
||||||
src="{{ url_for('web.get_cover', book_id=book.id, resolution='og', c=book|last_modified) }}"
|
src="{{ resized_img_src(url_for('web.get_cover', book_id=book.id, resolution='og', c=book|last_modified), format='webp') }}"
|
||||||
alt="{{ image_alt }}"
|
alt="{{ image_alt }}"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
{% set srcset = series|get_series_srcset %}
|
{% set srcset = series|get_series_srcset %}
|
||||||
<img
|
<img
|
||||||
srcset="{{ srcset }}"
|
srcset="{{ srcset }}"
|
||||||
src="{{ url_for('web.get_series_cover', series_id=series.id, resolution='og', c='day'|cache_timestamp) }}"
|
src="{{ resized_img_src(url_for('web.get_series_cover', series_id=series.id, resolution='og', c='day'|cache_timestamp), format='webp') }}"
|
||||||
alt="{{ book_title }}"
|
alt="{{ book_title }}"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
/>
|
/>
|
||||||
|
24
cps/web.py
24
cps/web.py
@@ -29,8 +29,6 @@ from flask import request, redirect, send_from_directory, make_response, flash,
|
|||||||
from flask import session as flask_session
|
from flask import session as flask_session
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
from flask_babel import get_locale
|
from flask_babel import get_locale
|
||||||
from flask_image_resizer import resized_img_src
|
|
||||||
|
|
||||||
from .cw_login import login_user, logout_user, current_user
|
from .cw_login import login_user, logout_user, current_user
|
||||||
from flask_limiter import RateLimitExceeded
|
from flask_limiter import RateLimitExceeded
|
||||||
from flask_limiter.util import get_remote_address
|
from flask_limiter.util import get_remote_address
|
||||||
@@ -1149,17 +1147,6 @@ def category_list():
|
|||||||
@web.route("/cover/<int:book_id>/<string:resolution>")
|
@web.route("/cover/<int:book_id>/<string:resolution>")
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def get_cover(book_id, resolution=None):
|
def get_cover(book_id, resolution=None):
|
||||||
return redirect(
|
|
||||||
resized_img_src(
|
|
||||||
url_for("web.get_raw_cover", book_id=book_id, resolution=resolution)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@web.route("/raw_cover/<int:book_id>")
|
|
||||||
@web.route("/raw_cover/<int:book_id>/<string:resolution>")
|
|
||||||
@login_required_if_no_ano
|
|
||||||
def get_raw_cover(book_id, resolution=None):
|
|
||||||
resolutions = {
|
resolutions = {
|
||||||
'og': constants.COVER_THUMBNAIL_ORIGINAL,
|
'og': constants.COVER_THUMBNAIL_ORIGINAL,
|
||||||
'sm': constants.COVER_THUMBNAIL_SMALL,
|
'sm': constants.COVER_THUMBNAIL_SMALL,
|
||||||
@@ -1174,17 +1161,6 @@ def get_raw_cover(book_id, resolution=None):
|
|||||||
@web.route("/series_cover/<int:series_id>/<string:resolution>")
|
@web.route("/series_cover/<int:series_id>/<string:resolution>")
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def get_series_cover(series_id, resolution=None):
|
def get_series_cover(series_id, resolution=None):
|
||||||
return redirect(
|
|
||||||
resized_img_src(
|
|
||||||
url_for("web.get_raw_series_cover", series_id=series_id, resolution=resolution)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@web.route("/raw_series_cover/<int:series_id>")
|
|
||||||
@web.route("/raw_series_cover/<int:series_id>/<string:resolution>")
|
|
||||||
@login_required_if_no_ano
|
|
||||||
def get_raw_series_cover(series_id, resolution=None):
|
|
||||||
resolutions = {
|
resolutions = {
|
||||||
'og': constants.COVER_THUMBNAIL_ORIGINAL,
|
'og': constants.COVER_THUMBNAIL_ORIGINAL,
|
||||||
'sm': constants.COVER_THUMBNAIL_SMALL,
|
'sm': constants.COVER_THUMBNAIL_SMALL,
|
||||||
|
Reference in New Issue
Block a user