From e0483882136e139304faa7dcce61cd08f82e3b15 Mon Sep 17 00:00:00 2001 From: Jef LeCompte Date: Fri, 3 Jul 2020 12:19:11 -0400 Subject: [PATCH] feat(api): include external port option Signed-off-by: Jef LeCompte --- cps/admin.py | 1 + cps/config_sql.py | 1 + cps/kobo.py | 14 ++++++-------- cps/templates/admin.html | 4 ++++ cps/templates/config_edit.html | 4 ++++ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 4fe027a2..cc4aacfb 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -623,6 +623,7 @@ def _configuration_update_helper(): gdriveError = _configuration_gdrive_helper(to_save) reboot_required |= _config_int(to_save, "config_port") + reboot_required |= _config_int(to_save, "config_external_port") reboot_required |= _config_string(to_save, "config_keyfile") if config.config_keyfile and not os.path.isfile(config.config_keyfile): diff --git a/cps/config_sql.py b/cps/config_sql.py index 1135516d..9c3a766b 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -57,6 +57,7 @@ class _Settings(_Base): config_calibre_dir = Column(String) config_port = Column(Integer, default=constants.DEFAULT_PORT) + config_external_port = Column(Integer, default=constants.DEFAULT_PORT) config_certfile = Column(String) config_keyfile = Column(String) diff --git a/cps/kobo.py b/cps/kobo.py index 97d55db0..573d9be3 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -267,14 +267,15 @@ def HandleMetadataRequest(book_uuid): def get_download_url_for_book(book, book_format): if not current_app.wsgi_app.is_proxied: - if ':' in request.host and not request.host.endswith(']') : + if ':' in request.host and not request.host.endswith(']'): host = "".join(request.host.split(':')[:-1]) else: host = request.host + return "{url_scheme}://{url_base}:{url_port}/download/{book_id}/{book_format}".format( url_scheme=request.scheme, url_base=host, - url_port=config.config_port, + url_port=config.config_external_port, book_id=book.id, book_format=book_format.lower() ) @@ -925,7 +926,7 @@ def HandleInitRequest(): calibre_web_url = "{url_scheme}://{url_base}:{url_port}".format( url_scheme=request.scheme, url_base=host, - url_port=config.config_port + url_port=config.config_external_port ) kobo_resources["image_host"] = calibre_web_url kobo_resources["image_url_quality_template"] = unquote(calibre_web_url + @@ -935,16 +936,14 @@ def HandleInitRequest(): width="{width}", height="{height}", Quality='{Quality}', - isGreyscale='isGreyscale' - )) + isGreyscale='isGreyscale')) kobo_resources["image_url_template"] = unquote(calibre_web_url + url_for("kobo.HandleCoverImageRequest", auth_token=kobo_auth.get_auth_token(), book_uuid="{ImageId}", width="{width}", height="{height}", - isGreyscale='false' - )) + isGreyscale='false')) else: kobo_resources["image_host"] = url_for("web.index", _external=True).strip("/") kobo_resources["image_url_quality_template"] = unquote(url_for("kobo.HandleCoverImageRequest", @@ -963,7 +962,6 @@ def HandleInitRequest(): isGreyscale='false', _external=True)) - response = make_response(jsonify({"Resources": kobo_resources})) response.headers["x-kobo-apitoken"] = "e30=" diff --git a/cps/templates/admin.html b/cps/templates/admin.html index a21fae48..d22c699b 100644 --- a/cps/templates/admin.html +++ b/cps/templates/admin.html @@ -88,6 +88,10 @@
{{_('Port')}}
{{config.config_port}}
+
+
{{_('External Port')}}
+
{{config.config_external_port}}
+
diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 77a60c1b..251545d8 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -90,6 +90,10 @@
+
+ + +