1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-18 14:10:30 +00:00

Fix cover upload url with spaces at the end

Support image/jpg as upload format mimetype, remove redundant check of mimetype
This commit is contained in:
Ozzie Isaacs 2022-04-12 19:33:00 +02:00
parent 028e6855a7
commit 83b99fcb1a
2 changed files with 17 additions and 15 deletions

View File

@ -810,7 +810,7 @@ def edit_book(book_id):
if to_save["cover_url"].endswith('/static/generic_cover.jpg'): if to_save["cover_url"].endswith('/static/generic_cover.jpg'):
book.has_cover = 0 book.has_cover = 0
else: else:
result, error = helper.save_cover_from_url(to_save["cover_url"], book.path) result, error = helper.save_cover_from_url(to_save["cover_url"].strip(), book.path)
if result is True: if result is True:
book.has_cover = 1 book.has_cover = 1
modify_date = True modify_date = True

View File

@ -753,6 +753,9 @@ def save_cover_from_url(url, book_path):
log.error("python modul advocate is not installed but is needed") log.error("python modul advocate is not installed but is needed")
return False, _("Python modul 'advocate' is not installed but is needed for cover downloads") return False, _("Python modul 'advocate' is not installed but is needed for cover downloads")
img.raise_for_status() img.raise_for_status()
# # cover_processing()
# move_coverfile(meta, db_book)
return save_cover(img, book_path) return save_cover(img, book_path)
except (socket.gaierror, except (socket.gaierror,
requests.exceptions.HTTPError, requests.exceptions.HTTPError,
@ -802,24 +805,23 @@ def save_cover(img, book_path):
content_type = img.headers.get('content-type') content_type = img.headers.get('content-type')
if use_IM: if use_IM:
if content_type not in ('image/jpeg', 'image/png', 'image/webp', 'image/bmp'): if content_type not in ('image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/bmp'):
log.error("Only jpg/jpeg/png/webp/bmp files are supported as coverfile") log.error("Only jpg/jpeg/png/webp/bmp files are supported as coverfile")
return False, _("Only jpg/jpeg/png/webp/bmp files are supported as coverfile") return False, _("Only jpg/jpeg/png/webp/bmp files are supported as coverfile")
# convert to jpg because calibre only supports jpg # convert to jpg because calibre only supports jpg
if content_type != 'image/jpg': try:
try: if hasattr(img, 'stream'):
if hasattr(img, 'stream'): imgc = Image(blob=img.stream)
imgc = Image(blob=img.stream) else:
else: imgc = Image(blob=io.BytesIO(img.content))
imgc = Image(blob=io.BytesIO(img.content)) imgc.format = 'jpeg'
imgc.format = 'jpeg' imgc.transform_colorspace("rgb")
imgc.transform_colorspace("rgb") img = imgc
img = imgc except (BlobError, MissingDelegateError):
except (BlobError, MissingDelegateError): log.error("Invalid cover file content")
log.error("Invalid cover file content") return False, _("Invalid cover file content")
return False, _("Invalid cover file content")
else: else:
if content_type not in 'image/jpeg': if content_type not in ['image/jpeg', 'image/jpg']:
log.error("Only jpg/jpeg files are supported as coverfile") log.error("Only jpg/jpeg files are supported as coverfile")
return False, _("Only jpg/jpeg files are supported as coverfile") return False, _("Only jpg/jpeg files are supported as coverfile")