mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-25 17:40:31 +00: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 jsonschema import validate, exceptions
|
||||||
from flask import Blueprint, request, make_response, jsonify, json
|
from flask import Blueprint, request, make_response, jsonify, json
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func, or_
|
||||||
|
|
||||||
from . import config, logger, kobo_auth, db, helper
|
from . import config, logger, kobo_auth, db, helper
|
||||||
from .web import download_required
|
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
|
# 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.
|
# the comparison because of the +00:00 suffix.
|
||||||
changed_entries = (
|
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(func.datetime(db.Books.last_modified) != sync_token.books_last_modified)
|
||||||
|
.filter(or_(db.Data.format == 'KEPUB', db.Data.format == 'EPUB'))
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
for book in changed_entries:
|
for book in changed_entries:
|
||||||
@ -217,9 +218,9 @@ def HandleMetadataRequest(book_uuid):
|
|||||||
|
|
||||||
def get_download_url_for_book(book, book_format):
|
def get_download_url_for_book(book, book_format):
|
||||||
return "{url_base}/download/{book_id}/{book_format}".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_id=book.id,
|
||||||
book_format=book_format.lower(),
|
book_format="kepub",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -272,14 +273,14 @@ def get_series(book):
|
|||||||
|
|
||||||
|
|
||||||
def get_metadata(book):
|
def get_metadata(book):
|
||||||
ALLOWED_FORMATS = {"KEPUB"}
|
ALLOWED_FORMATS = {"KEPUB", "EPUB"}
|
||||||
download_urls = []
|
download_urls = []
|
||||||
|
|
||||||
for book_data in book.data:
|
for book_data in book.data:
|
||||||
if book_data.format in ALLOWED_FORMATS:
|
if book_data.format in ALLOWED_FORMATS:
|
||||||
download_urls.append(
|
download_urls.append(
|
||||||
{
|
{
|
||||||
"Format": book_data.format,
|
"Format": "KEPUB",
|
||||||
"Size": book_data.uncompressed_size,
|
"Size": book_data.uncompressed_size,
|
||||||
"Url": get_download_url_for_book(book, book_data.format),
|
"Url": get_download_url_for_book(book, book_data.format),
|
||||||
# "DrmType": "None", # Not required
|
# "DrmType": "None", # Not required
|
||||||
@ -385,9 +386,12 @@ def HandleAuthRequest():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def get_base_url():
|
||||||
|
return "{root}:{port}".format(root=request.url_root[:-1], port=str(config.config_port))
|
||||||
|
|
||||||
@kobo.route("/v1/initialization")
|
@kobo.route("/v1/initialization")
|
||||||
def HandleInitRequest():
|
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 = make_response(jsonify({"Resources": resources}))
|
||||||
response.headers["x-kobo-apitoken"] = "e30="
|
response.headers["x-kobo-apitoken"] = "e30="
|
||||||
return response
|
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)
|
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>")
|
@web.route("/download/<int:book_id>/<book_format>")
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
@download_required
|
@download_required
|
||||||
def download_link(book_id, book_format):
|
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)
|
return get_download_link(book_id, book_format)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user