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:
20
cps/web.py
20
cps/web.py
@@ -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'})
|
||||
|
||||
Reference in New Issue
Block a user