mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 09:30:31 +00:00
Fix #163
This commit is contained in:
parent
ebb3acecca
commit
395c6679b7
21
cps/web.py
21
cps/web.py
@ -32,6 +32,7 @@ from flask_babel import gettext as _
|
|||||||
import requests
|
import requests
|
||||||
import zipfile
|
import zipfile
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
from werkzeug.datastructures import Headers
|
||||||
from babel import Locale as LC
|
from babel import Locale as LC
|
||||||
from babel import negotiate_locale
|
from babel import negotiate_locale
|
||||||
from babel import __version__ as babelVersion
|
from babel import __version__ as babelVersion
|
||||||
@ -52,12 +53,9 @@ import db
|
|||||||
from shutil import move, copyfile
|
from shutil import move, copyfile
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
import shutil
|
import shutil
|
||||||
import StringIO
|
|
||||||
import gdriveutils
|
import gdriveutils
|
||||||
import tempfile
|
import tempfile
|
||||||
import io
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import threading
|
|
||||||
|
|
||||||
from tornado import version as tornadoVersion
|
from tornado import version as tornadoVersion
|
||||||
|
|
||||||
@ -81,7 +79,6 @@ try:
|
|||||||
use_generic_pdf_cover = False
|
use_generic_pdf_cover = False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
use_generic_pdf_cover = True
|
use_generic_pdf_cover = True
|
||||||
from cgi import escape
|
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
gdrive_watch_callback_token='target=calibreweb-watch_files'
|
gdrive_watch_callback_token='target=calibreweb-watch_files'
|
||||||
@ -825,18 +822,18 @@ def get_opds_download_link(book_id, format):
|
|||||||
if len(book.authors) > 0:
|
if len(book.authors) > 0:
|
||||||
file_name = book.authors[0].name + '_' + file_name
|
file_name = book.authors[0].name + '_' + file_name
|
||||||
file_name = helper.get_valid_filename(file_name)
|
file_name = helper.get_valid_filename(file_name)
|
||||||
headers={}
|
headers = Headers ()
|
||||||
headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (quote(file_name.encode('utf8')), format)
|
headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (quote(file_name.encode('utf8')), format)
|
||||||
app.logger.info (time.time()-startTime)
|
app.logger.info (time.time()-startTime)
|
||||||
startTime=time.time()
|
startTime=time.time()
|
||||||
if config.config_use_google_drive:
|
if config.config_use_google_drive:
|
||||||
|
app.logger.info(time.time() - startTime)
|
||||||
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, book.path, data.name + "." + format)
|
df=gdriveutils.getFileFromEbooksFolder(Gdrive.Instance().drive, book.path, data.name + "." + format)
|
||||||
return do_gdrive_download(df, headers)
|
return do_gdrive_download(df, headers)
|
||||||
else:
|
else:
|
||||||
# file_name = helper.get_valid_filename(file_name)
|
|
||||||
response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
|
response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
|
||||||
response.headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (quote(file_name.encode('utf8')), format)
|
response.headers=headers
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.route("/ajax/book/<string:uuid>")
|
@app.route("/ajax/book/<string:uuid>")
|
||||||
@ -1388,7 +1385,7 @@ def shutdown():
|
|||||||
def update():
|
def update():
|
||||||
helper.updater_thread = helper.Updater()
|
helper.updater_thread = helper.Updater()
|
||||||
flash(_(u"Update done"), category="info")
|
flash(_(u"Update done"), category="info")
|
||||||
return ""
|
return abort(404)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/search", methods=["GET"])
|
@app.route("/search", methods=["GET"])
|
||||||
@ -1639,7 +1636,7 @@ def get_download_link(book_id, format):
|
|||||||
if len(book.authors) > 0:
|
if len(book.authors) > 0:
|
||||||
file_name = book.authors[0].name + '_' + file_name
|
file_name = book.authors[0].name + '_' + file_name
|
||||||
file_name = helper.get_valid_filename(file_name)
|
file_name = helper.get_valid_filename(file_name)
|
||||||
headers={}
|
headers = Headers ()
|
||||||
try:
|
try:
|
||||||
headers["Content-Type"] = mimetypes.types_map['.' + format]
|
headers["Content-Type"] = mimetypes.types_map['.' + format]
|
||||||
except:
|
except:
|
||||||
@ -1650,8 +1647,8 @@ def get_download_link(book_id, format):
|
|||||||
return do_gdrive_download(df, headers)
|
return do_gdrive_download(df, headers)
|
||||||
else:
|
else:
|
||||||
response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
|
response = make_response(send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + format))
|
||||||
response.headers["Content-Disposition"] = "attachment; filename*=UTF-8''%s.%s" % (quote(file_name.encode('utf-8')), format)
|
response.headers=headers
|
||||||
return response
|
return response
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user