Merge remote-tracking branch 'kepubify/Develop' into Develop

# Conflicts:
#	cps/admin.py
#	cps/helper.py
#	cps/templates/config_edit.html
#	cps/web.py
This commit is contained in:
Ozzieisaacs 2020-05-08 14:53:21 +02:00
commit a437c603c6
5 changed files with 41 additions and 5 deletions

View File

@ -538,6 +538,11 @@ def _configuration_update_helper():
_config_string("config_converterpath") _config_string("config_converterpath")
_config_string("config_kepubifypath") _config_string("config_kepubifypath")
_config_checkbox_int("config_automatic_kepub")
_config_string("config_kepubify_path")
_config_string("config_kepub_cache_dir")
reboot_required |= _config_int("config_login_type") reboot_required |= _config_int("config_login_type")
#LDAP configurator, #LDAP configurator,

View File

@ -124,6 +124,10 @@ class _Settings(_Base):
config_rarfile_location = Column(String) config_rarfile_location = Column(String)
config_upload_formats = Column(String, default=','.join(constants.EXTENSIONS_UPLOAD)) config_upload_formats = Column(String, default=','.join(constants.EXTENSIONS_UPLOAD))
config_automatic_kepub = Column(Boolean, default=False)
config_kepubify_path = Column(String)
config_kepub_cache_dir = Column(String)
config_updatechannel = Column(Integer, default=constants.UPDATE_STABLE) config_updatechannel = Column(Integer, default=constants.UPDATE_STABLE)
config_reverse_proxy_login_header_name = Column(String) config_reverse_proxy_login_header_name = Column(String)

View File

@ -593,7 +593,8 @@ def save_cover(img, book_path):
return save_cover_from_filestorage(os.path.join(config.config_calibre_dir, book_path), "cover.jpg", img) return save_cover_from_filestorage(os.path.join(config.config_calibre_dir, book_path), "cover.jpg", img)
def do_download_file(book, book_format, data, headers):
def do_download_file(book, book_format, client, data, headers):
if config.config_use_google_drive: if config.config_use_google_drive:
startTime = time.time() startTime = time.time()
df = gd.getFileFromEbooksFolder(book.path, data.name + "." + book_format) df = gd.getFileFromEbooksFolder(book.path, data.name + "." + book_format)
@ -607,7 +608,18 @@ def do_download_file(book, book_format, data, headers):
if not os.path.isfile(os.path.join(filename, data.name + "." + book_format)): if not os.path.isfile(os.path.join(filename, data.name + "." + book_format)):
# ToDo: improve error handling # ToDo: improve error handling
log.error('File not found: %s', os.path.join(filename, data.name + "." + book_format)) log.error('File not found: %s', os.path.join(filename, data.name + "." + book_format))
if client == "kobo" and book_format == "epub":
filename = config.config_kepub_cache_dir
os.system('{0} "{1}" -o {2}'.format(
config.config_kepubify_path,
os.path.join(filename, data.name + "." + book_format),
filename))
book_format = "kepub.epub"
headers["Content-Disposition"] = headers["Content-Disposition"].replace(".epub", ".kepub.epub")
response = make_response(send_from_directory(filename, data.name + "." + book_format)) response = make_response(send_from_directory(filename, data.name + "." + book_format))
response.headers = headers response.headers = headers
return response return response
@ -876,8 +888,7 @@ def get_cc_columns(filter_config_custom_read=False):
return cc return cc
def get_download_link(book_id, book_format, client):
def get_download_link(book_id, book_format):
book_format = book_format.split(".")[0] book_format = book_format.split(".")[0]
book = db.session.query(db.Books).filter(db.Books.id == book_id).filter(common_filters()).first() book = db.session.query(db.Books).filter(db.Books.id == book_id).filter(common_filters()).first()
if book: if book:
@ -897,7 +908,7 @@ def get_download_link(book_id, book_format):
headers["Content-Type"] = mimetypes.types_map.get('.' + book_format, "application/octet-stream") headers["Content-Type"] = mimetypes.types_map.get('.' + book_format, "application/octet-stream")
headers["Content-Disposition"] = "attachment; filename=%s.%s; filename*=UTF-8''%s.%s" % ( headers["Content-Disposition"] = "attachment; filename=%s.%s; filename*=UTF-8''%s.%s" % (
quote(file_name.encode('utf-8')), book_format, quote(file_name.encode('utf-8')), book_format) quote(file_name.encode('utf-8')), book_format, quote(file_name.encode('utf-8')), book_format)
return do_download_file(book, book_format, data1, headers) return do_download_file(book, book_format, client, data1, headers)
else: else:
abort(404) abort(404)

View File

@ -363,6 +363,18 @@
<button type="button" id="kepubify_path" class="btn btn-default"><span class="glyphicon glyphicon-folder-open"></span></button> <button type="button" id="kepubify_path" class="btn btn-default"><span class="glyphicon glyphicon-folder-open"></span></button>
</span> </span>
</div> </div>
<div class="form-group">
<input type="checkbox" id="config_automatic_kepub" name="config_automatic_kepub" {% if config.config_automatic_kepub %}checked{% endif %}>
<label for="config_uploading">{{_('Enable automatic kobo epub conversion')}}</label>
</div>
<div class="form-group">
<label for="config_kepubify_path">{{_('Path to kepubify')}}</label>
<input type="text" class="form-control" id="config_kepubify_path" name="config_kepubify_path" value="{% if config.config_kepubify_path != None %}{{ config.config_kepubify_path }}{% endif %}" autocomplete="off">
</div>
<div class="form-group">
<label for="config_kepub_cache_dir">{{_('Path to kepubify')}}</label>
<input type="text" class="form-control" id="config_kepub_cache_dir" name="config_kepub_cache_dir" value="{% if config.config_kepub_cache_dir != None %}{{ config.config_kepub_cache_dir }}{% endif %}" autocomplete="off">
</div>
{% if feature_support['rar'] %} {% if feature_support['rar'] %}
<label for="config_rarfile_location">{{_('Location of Unrar binary')}}</label> <label for="config_rarfile_location">{{_('Location of Unrar binary')}}</label>
<div class="form-group input-group"> <div class="form-group input-group">

View File

@ -1233,7 +1233,11 @@ def serve_book(book_id, book_format, anyname):
@login_required_if_no_ano @login_required_if_no_ano
@download_required @download_required
def download_link(book_id, book_format, anyname): def download_link(book_id, book_format, anyname):
return get_download_link(book_id, book_format.lower()) if (config.config_automatic_kepub and
"Kobo" in request.headers.get('User-Agent')):
client = "kobo"
return get_download_link(book_id, book_format, client)
@web.route('/send/<int:book_id>/<book_format>/<int:convert>') @web.route('/send/<int:book_id>/<book_format>/<int:convert>')