|
|
@ -315,8 +315,15 @@ def get_description(book):
|
|
|
|
# TODO handle multiple authors
|
|
|
|
# TODO handle multiple authors
|
|
|
|
def get_author(book):
|
|
|
|
def get_author(book):
|
|
|
|
if not book.authors:
|
|
|
|
if not book.authors:
|
|
|
|
return None
|
|
|
|
return {"Contributors": None}
|
|
|
|
return book.authors[0].name
|
|
|
|
if len(book.authors) > 1:
|
|
|
|
|
|
|
|
author_list = []
|
|
|
|
|
|
|
|
autor_roles = []
|
|
|
|
|
|
|
|
for author in book.authors:
|
|
|
|
|
|
|
|
autor_roles.append({"Name":author.name, "Role":"Author"})
|
|
|
|
|
|
|
|
author_list.append(author.name)
|
|
|
|
|
|
|
|
return {"ContributorRoles": autor_roles, "Contributors":author_list}
|
|
|
|
|
|
|
|
return {"ContributorRoles": [{"Name":book.authors[0].name, "Role":"Author"}], "Contributors": book.authors[0].name}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_publisher(book):
|
|
|
|
def get_publisher(book):
|
|
|
@ -355,7 +362,7 @@ def get_metadata(book):
|
|
|
|
book_uuid = book.uuid
|
|
|
|
book_uuid = book.uuid
|
|
|
|
metadata = {
|
|
|
|
metadata = {
|
|
|
|
"Categories": ["00000000-0000-0000-0000-000000000001",],
|
|
|
|
"Categories": ["00000000-0000-0000-0000-000000000001",],
|
|
|
|
"Contributors": get_author(book),
|
|
|
|
# "Contributors": get_author(book),
|
|
|
|
"CoverImageId": book_uuid,
|
|
|
|
"CoverImageId": book_uuid,
|
|
|
|
"CrossRevisionId": book_uuid,
|
|
|
|
"CrossRevisionId": book_uuid,
|
|
|
|
"CurrentDisplayPrice": {"CurrencyCode": "USD", "TotalAmount": 0},
|
|
|
|
"CurrentDisplayPrice": {"CurrencyCode": "USD", "TotalAmount": 0},
|
|
|
@ -379,6 +386,7 @@ def get_metadata(book):
|
|
|
|
"Title": book.title,
|
|
|
|
"Title": book.title,
|
|
|
|
"WorkId": book_uuid,
|
|
|
|
"WorkId": book_uuid,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata.update(get_author(book))
|
|
|
|
|
|
|
|
|
|
|
|
if get_series(book):
|
|
|
|
if get_series(book):
|
|
|
|
if sys.version_info < (3, 0):
|
|
|
|
if sys.version_info < (3, 0):
|
|
|
@ -397,7 +405,7 @@ def get_metadata(book):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kobo.route("/v1/library/tags", methods=["POST", "DELETE"])
|
|
|
|
@kobo.route("/v1/library/tags", methods=["POST", "DELETE"])
|
|
|
|
@login_required
|
|
|
|
@requires_kobo_auth
|
|
|
|
# Creates a Shelf with the given items, and returns the shelf's uuid.
|
|
|
|
# Creates a Shelf with the given items, and returns the shelf's uuid.
|
|
|
|
def HandleTagCreate():
|
|
|
|
def HandleTagCreate():
|
|
|
|
# catch delete requests, otherwise the are handeld in the book delete handler
|
|
|
|
# catch delete requests, otherwise the are handeld in the book delete handler
|
|
|
@ -432,6 +440,7 @@ def HandleTagCreate():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kobo.route("/v1/library/tags/<tag_id>", methods=["DELETE", "PUT"])
|
|
|
|
@kobo.route("/v1/library/tags/<tag_id>", methods=["DELETE", "PUT"])
|
|
|
|
|
|
|
|
@requires_kobo_auth
|
|
|
|
def HandleTagUpdate(tag_id):
|
|
|
|
def HandleTagUpdate(tag_id):
|
|
|
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.uuid == tag_id,
|
|
|
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.uuid == tag_id,
|
|
|
|
ub.Shelf.user_id == current_user.id).one_or_none()
|
|
|
|
ub.Shelf.user_id == current_user.id).one_or_none()
|
|
|
@ -486,7 +495,7 @@ def add_items_to_shelf(items, shelf):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kobo.route("/v1/library/tags/<tag_id>/items", methods=["POST"])
|
|
|
|
@kobo.route("/v1/library/tags/<tag_id>/items", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
@requires_kobo_auth
|
|
|
|
def HandleTagAddItem(tag_id):
|
|
|
|
def HandleTagAddItem(tag_id):
|
|
|
|
items = None
|
|
|
|
items = None
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -516,7 +525,7 @@ def HandleTagAddItem(tag_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kobo.route("/v1/library/tags/<tag_id>/items/delete", methods=["POST"])
|
|
|
|
@kobo.route("/v1/library/tags/<tag_id>/items/delete", methods=["POST"])
|
|
|
|
@login_required
|
|
|
|
@requires_kobo_auth
|
|
|
|
def HandleTagRemoveItem(tag_id):
|
|
|
|
def HandleTagRemoveItem(tag_id):
|
|
|
|
items = None
|
|
|
|
items = None
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -625,7 +634,7 @@ def create_kobo_tag(shelf):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kobo.route("/v1/library/<book_uuid>/state", methods=["GET", "PUT"])
|
|
|
|
@kobo.route("/v1/library/<book_uuid>/state", methods=["GET", "PUT"])
|
|
|
|
@login_required
|
|
|
|
@requires_kobo_auth
|
|
|
|
def HandleStateRequest(book_uuid):
|
|
|
|
def HandleStateRequest(book_uuid):
|
|
|
|
book = calibre_db.get_book_by_uuid(book_uuid)
|
|
|
|
book = calibre_db.get_book_by_uuid(book_uuid)
|
|
|
|
if not book or not book.data:
|
|
|
|
if not book or not book.data:
|
|
|
@ -799,7 +808,7 @@ def TopLevelEndpoint():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@kobo.route("/v1/library/<book_uuid>", methods=["DELETE"])
|
|
|
|
@kobo.route("/v1/library/<book_uuid>", methods=["DELETE"])
|
|
|
|
@login_required
|
|
|
|
@requires_kobo_auth
|
|
|
|
def HandleBookDeletionRequest(book_uuid):
|
|
|
|
def HandleBookDeletionRequest(book_uuid):
|
|
|
|
log.info("Kobo book deletion request received for book %s" % book_uuid)
|
|
|
|
log.info("Kobo book deletion request received for book %s" % book_uuid)
|
|
|
|
book = calibre_db.get_book_by_uuid(book_uuid)
|
|
|
|
book = calibre_db.get_book_by_uuid(book_uuid)
|
|
|
|