mirror of
https://github.com/janeczku/calibre-web.git
synced 2024-11-26 08:51:05 +02:00
Update Kobo sync
This commit is contained in:
parent
f705889c23
commit
f2c07d8f81
18
cps/kobo.py
18
cps/kobo.py
@ -27,7 +27,7 @@ from time import gmtime, strftime
|
||||
from jsonschema import validate, exceptions
|
||||
from flask import Blueprint, request, make_response, jsonify, json
|
||||
from flask_login import login_required
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy import func, or_
|
||||
|
||||
from . import config, logger, kobo_auth, db, helper
|
||||
from .web import download_required
|
||||
@ -166,8 +166,9 @@ def HandleSyncRequest():
|
||||
# It looks like it's treating the db.Books.last_modified field as a string and may fail
|
||||
# the comparison because of the +00:00 suffix.
|
||||
changed_entries = (
|
||||
db.session.query(db.Books)
|
||||
db.session.query(db.Books).join(db.Data)
|
||||
.filter(func.datetime(db.Books.last_modified) != sync_token.books_last_modified)
|
||||
.filter(or_(db.Data.format == 'KEPUB', db.Data.format == 'EPUB'))
|
||||
.all()
|
||||
)
|
||||
for book in changed_entries:
|
||||
@ -217,9 +218,9 @@ def HandleMetadataRequest(book_uuid):
|
||||
|
||||
def get_download_url_for_book(book, book_format):
|
||||
return "{url_base}/download/{book_id}/{book_format}".format(
|
||||
url_base=request.environ['werkzeug.request'].base_url,
|
||||
url_base=get_base_url(), # request.environ['werkzeug.request'].base_url,
|
||||
book_id=book.id,
|
||||
book_format=book_format.lower(),
|
||||
book_format="kepub",
|
||||
)
|
||||
|
||||
|
||||
@ -272,14 +273,14 @@ def get_series(book):
|
||||
|
||||
|
||||
def get_metadata(book):
|
||||
ALLOWED_FORMATS = {"KEPUB"}
|
||||
ALLOWED_FORMATS = {"KEPUB", "EPUB"}
|
||||
download_urls = []
|
||||
|
||||
for book_data in book.data:
|
||||
if book_data.format in ALLOWED_FORMATS:
|
||||
download_urls.append(
|
||||
{
|
||||
"Format": book_data.format,
|
||||
"Format": "KEPUB",
|
||||
"Size": book_data.uncompressed_size,
|
||||
"Url": get_download_url_for_book(book, book_data.format),
|
||||
# "DrmType": "None", # Not required
|
||||
@ -385,9 +386,12 @@ def HandleAuthRequest():
|
||||
return response
|
||||
|
||||
|
||||
def get_base_url():
|
||||
return "{root}:{port}".format(root=request.url_root[:-1], port=str(config.config_port))
|
||||
|
||||
@kobo.route("/v1/initialization")
|
||||
def HandleInitRequest():
|
||||
resources = NATIVE_KOBO_RESOURCES(calibre_web_url=config.config_server_url)
|
||||
resources = NATIVE_KOBO_RESOURCES(calibre_web_url=get_base_url())
|
||||
response = make_response(jsonify({"Resources": resources}))
|
||||
response.headers["x-kobo-apitoken"] = "e30="
|
||||
return response
|
||||
|
@ -1029,11 +1029,13 @@ def serve_book(book_id, book_format, anyname):
|
||||
return send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format)
|
||||
|
||||
|
||||
# @web.route("/download/<int:book_id>/<book_format>", defaults={'anyname': 'None'})
|
||||
@web.route("/download/<int:book_id>/<book_format>")
|
||||
@login_required_if_no_ano
|
||||
@download_required
|
||||
def download_link(book_id, book_format):
|
||||
if book_format.lower() == "kepub":
|
||||
book_format= "epub"
|
||||
log.info("Book %s in format %s downloaded", str(book_id), book_format)
|
||||
return get_download_link(book_id, book_format)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user