From ae33aee3f6bc70261111d08ad8d750833a8d7705 Mon Sep 17 00:00:00 2001 From: Julian Naydichev Date: Sat, 31 Oct 2020 14:50:08 +0100 Subject: [PATCH] When serving a download URL via KoboSync, use a URL that is specific to Kobo --- cps/kobo.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cps/kobo.py b/cps/kobo.py index a6dfc3f6..dbbdb8c9 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -47,9 +47,10 @@ from sqlalchemy.exc import StatementError import requests from . import config, logger, kobo_auth, db, calibre_db, helper, shelf as shelf_lib, ub +from .helper import get_download_link from .services import SyncToken as SyncToken from .web import download_required -from .kobo_auth import requires_kobo_auth +from .kobo_auth import requires_kobo_auth, get_auth_token KOBO_FORMATS = {"KEPUB": ["KEPUB"], "EPUB": ["EPUB3", "EPUB"]} KOBO_STOREAPI_URL = "https://storeapi.kobo.com" @@ -270,10 +271,11 @@ def get_download_url_for_book(book, book_format): else: host = request.host - return "{url_scheme}://{url_base}:{url_port}/download/{book_id}/{book_format}".format( + return "{url_scheme}://{url_base}:{url_port}/kobo/{auth_token}/download/{book_id}/{book_format}".format( url_scheme=request.scheme, url_base=host, url_port=config.config_external_port, + auth_token=get_auth_token(), book_id=book.id, book_format=book_format.lower() ) @@ -976,6 +978,14 @@ def HandleInitRequest(): return response +@kobo.route("/download//") +@requires_kobo_auth +@download_required +def download_book(book_id, book_format): + + return get_download_link(book_id, book_format, "kobo") + + def NATIVE_KOBO_RESOURCES(): return { "account_page": "https://secure.kobobooks.com/profile",