Fix for #1227 (Download books not possible with gevent IPV6 connection)

Fix issue where books aren't correctly ordered by Date Added
This commit is contained in:
Ozzieisaacs 2020-02-26 20:05:44 +01:00
commit 202b6121ab

View File

@ -21,6 +21,7 @@ import sys
import base64 import base64
import os import os
import uuid import uuid
from datetime import datetime
from time import gmtime, strftime from time import gmtime, strftime
try: try:
from urllib import unquote from urllib import unquote
@ -213,13 +214,22 @@ def HandleMetadataRequest(book_uuid):
def get_download_url_for_book(book, book_format): def get_download_url_for_book(book, book_format):
if not current_app.wsgi_app.is_proxied: if not current_app.wsgi_app.is_proxied:
return "{url_scheme}://{url_base}:{url_port}/download/{book_id}/{book_format}".format( if request.environ['SERVER_NAME'] != '::':
url_scheme=request.environ['wsgi.url_scheme'], return "{url_scheme}://{url_base}:{url_port}/download/{book_id}/{book_format}".format(
url_base=request.environ['SERVER_NAME'], url_scheme=request.environ['wsgi.url_scheme'],
url_port=config.config_port, url_base=request.environ['SERVER_NAME'],
book_id=book.id, url_port=config.config_port,
book_format=book_format.lower() book_id=book.id,
) book_format=book_format.lower()
)
else:
return "{url_scheme}://{url_base}:{url_port}/download/{book_id}/{book_format}".format(
url_scheme=request.environ['wsgi.url_scheme'],
url_base=request.host, # ToDo: both server ??
url_port=config.config_port,
book_id=book.id,
book_format=book_format.lower()
)
else: else:
return url_for( return url_for(
"web.download_link", "web.download_link",
@ -234,14 +244,14 @@ def create_book_entitlement(book):
return { return {
"Accessibility": "Full", "Accessibility": "Full",
"ActivePeriod": {"From": current_time(),}, "ActivePeriod": {"From": current_time(),},
"Created": book.timestamp, "Created": book.timestamp.strftime("%Y-%m-%dT%H:%M:%SZ"),
"CrossRevisionId": book_uuid, "CrossRevisionId": book_uuid,
"Id": book_uuid, "Id": book_uuid,
"IsHiddenFromArchive": False, "IsHiddenFromArchive": False,
"IsLocked": False, "IsLocked": False,
# Setting this to true removes from the device. # Setting this to true removes from the device.
"IsRemoved": False, "IsRemoved": False,
"LastModified": book.last_modified, "LastModified": book.last_modified.strftime("%Y-%m-%dT%H:%M:%SZ"),
"OriginCategory": "Imported", "OriginCategory": "Imported",
"RevisionId": book_uuid, "RevisionId": book_uuid,
"Status": "Active", "Status": "Active",
@ -376,7 +386,7 @@ def TopLevelEndpoint():
@kobo.route("/v1/library/tags/<shelf_name>", methods=["POST"]) @kobo.route("/v1/library/tags/<shelf_name>", methods=["POST"])
@kobo.route("/v1/library/tags/<tag_id>", methods=["DELETE"]) @kobo.route("/v1/library/tags/<tag_id>", methods=["DELETE"])
def HandleUnimplementedRequest(dummy=None, book_uuid=None, shelf_name=None, tag_id=None): def HandleUnimplementedRequest(dummy=None, book_uuid=None, shelf_name=None, tag_id=None):
log.debug("Alternative Request received:") log.debug("Unimplemented Library Request received: %s", request.base_url)
return redirect_or_proxy_request() return redirect_or_proxy_request()
@ -397,6 +407,7 @@ def HandleUserRequest(dummy=None):
@kobo.route("/v1/products/<dummy>/reviews", methods=["GET", "POST"]) @kobo.route("/v1/products/<dummy>/reviews", methods=["GET", "POST"])
@kobo.route("/v1/products/books/<dummy>", methods=["GET", "POST"]) @kobo.route("/v1/products/books/<dummy>", methods=["GET", "POST"])
@kobo.route("/v1/products/dailydeal", methods=["GET", "POST"]) @kobo.route("/v1/products/dailydeal", methods=["GET", "POST"])
@kobo.route("/v1/products", methods=["GET", "POST"])
def HandleProductsRequest(dummy=None): def HandleProductsRequest(dummy=None):
log.debug("Unimplemented Products Request received: %s", request.base_url) log.debug("Unimplemented Products Request received: %s", request.base_url)
return redirect_or_proxy_request() return redirect_or_proxy_request()