1
0
mirror of https://github.com/janeczku/calibre-web synced 2025-10-24 11:57:40 +00:00

Bugfixes from testrun

This commit is contained in:
Ozzie Isaacs
2023-02-22 18:59:11 +01:00
parent fc31132f4e
commit 162ac73bee
3 changed files with 248 additions and 74 deletions

View File

@@ -1161,18 +1161,15 @@ def serve_book(book_id, book_format, anyname):
data = calibre_db.get_book_format(book_id, book_format.upper())
if not data:
return "File not in Database"
range_header = request.headers.get('Range', None)
if not range_header:
log.info('Serving book: %s', data.name)
response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format))
response.headers['Accept-Ranges'] = 'bytes'
return response
if config.config_use_google_drive:
try:
headers = Headers()
headers["Content-Type"] = mimetypes.types_map.get('.' + book_format, "application/octet-stream")
if not range_header:
log.info('Serving book: %s', data.name)
headers['Accept-Ranges'] = 'bytes'
df = getFileFromEbooksFolder(book.path, data.name + "." + book_format)
return do_gdrive_download(df, headers, (book_format.upper() == 'TXT'))
except AttributeError as ex:
@@ -1180,6 +1177,7 @@ def serve_book(book_id, book_format, anyname):
return "File Not Found"
else:
if book_format.upper() == 'TXT':
log.info('Serving book: %s', data.name)
try:
rawdata = open(os.path.join(config.config_calibre_dir, book.path, data.name + "." + book_format),
"rb").read()
@@ -1189,7 +1187,13 @@ def serve_book(book_id, book_format, anyname):
except FileNotFoundError:
log.error("File Not Found")
return "File Not Found"
return send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format)
# enable byte range read of pdf
response = make_response(
send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format))
if not range_header:
log.info('Serving book: %s', data.name)
response.headers['Accept-Ranges'] = 'bytes'
return response
@web.route("/download/<int:book_id>/<book_format>", defaults={'anyname': 'None'})