mirror of
https://github.com/janeczku/calibre-web
synced 2024-09-28 23:10:48 +00:00
Sync public shelves to Kobo reader for all users
This commit is contained in:
parent
07c67b09db
commit
d84865073b
32
cps/kobo.py
32
cps/kobo.py
@ -184,7 +184,7 @@ def HandleSyncRequest():
|
|||||||
.order_by(ub.ArchivedBook.last_modified)
|
.order_by(ub.ArchivedBook.last_modified)
|
||||||
.join(ub.BookShelf, db.Books.id == ub.BookShelf.book_id)
|
.join(ub.BookShelf, db.Books.id == ub.BookShelf.book_id)
|
||||||
.join(ub.Shelf)
|
.join(ub.Shelf)
|
||||||
.filter(ub.Shelf.user_id == current_user.id)
|
.filter(or_(ub.Shelf.user_id == current_user.id, ub.Shelf.is_public == 1))
|
||||||
.filter(ub.Shelf.kobo_sync)
|
.filter(ub.Shelf.kobo_sync)
|
||||||
.distinct())
|
.distinct())
|
||||||
else:
|
else:
|
||||||
@ -282,7 +282,7 @@ def HandleSyncRequest():
|
|||||||
changed_reading_states = changed_reading_states.join(ub.BookShelf,
|
changed_reading_states = changed_reading_states.join(ub.BookShelf,
|
||||||
ub.KoboReadingState.book_id == ub.BookShelf.book_id)\
|
ub.KoboReadingState.book_id == ub.BookShelf.book_id)\
|
||||||
.join(ub.Shelf)\
|
.join(ub.Shelf)\
|
||||||
.filter(current_user.id == ub.Shelf.user_id)\
|
.filter(or_(current_user.id == ub.Shelf.user_id, ub.Shelf.is_public == 1))\
|
||||||
.filter(ub.Shelf.kobo_sync,
|
.filter(ub.Shelf.kobo_sync,
|
||||||
or_(
|
or_(
|
||||||
ub.KoboReadingState.last_modified > sync_token.reading_state_last_modified,
|
ub.KoboReadingState.last_modified > sync_token.reading_state_last_modified,
|
||||||
@ -523,8 +523,10 @@ def HandleTagCreate():
|
|||||||
abort(400, description="Malformed tags POST request. Data has empty 'Name', missing 'Name' or 'Items' field")
|
abort(400, description="Malformed tags POST request. Data has empty 'Name', missing 'Name' or 'Items' field")
|
||||||
|
|
||||||
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.name == name, ub.Shelf.user_id ==
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.name == name, ub.Shelf.user_id ==
|
||||||
current_user.id).one_or_none()
|
or_(current_user.id,
|
||||||
|
ub.Shelf.is_public == 1)).one_or_none()
|
||||||
if shelf and not shelf_lib.check_shelf_edit_permissions(shelf):
|
if shelf and not shelf_lib.check_shelf_edit_permissions(shelf):
|
||||||
|
log.debug("User is unauthaurized to create shelf.")
|
||||||
abort(401, description="User is unauthaurized to create shelf.")
|
abort(401, description="User is unauthaurized to create shelf.")
|
||||||
|
|
||||||
if not shelf:
|
if not shelf:
|
||||||
@ -543,9 +545,10 @@ def HandleTagCreate():
|
|||||||
@requires_kobo_auth
|
@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()
|
or_(ub.Shelf.user_id == current_user.id,
|
||||||
|
ub.Shelf.is_public == 1)).one_or_none()
|
||||||
if not shelf:
|
if not shelf:
|
||||||
log.debug("Received Kobo tag update request on a collection unknown to CalibreWeb")
|
log.debug("Received Kobo tag update request on a collection unknown to CalibreWeb: " + str(tag_id))
|
||||||
if config.config_kobo_proxy:
|
if config.config_kobo_proxy:
|
||||||
return redirect_or_proxy_request()
|
return redirect_or_proxy_request()
|
||||||
else:
|
else:
|
||||||
@ -605,12 +608,14 @@ def HandleTagAddItem(tag_id):
|
|||||||
abort(400, description="Malformed tags POST request. Data is missing 'Items' field")
|
abort(400, description="Malformed tags POST request. Data is missing 'Items' field")
|
||||||
|
|
||||||
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()
|
or_(ub.Shelf.user_id == current_user.id,
|
||||||
|
ub.Shelf.is_public == 1)).one_or_none()
|
||||||
if not shelf:
|
if not shelf:
|
||||||
log.debug("Received Kobo request on a collection unknown to CalibreWeb")
|
log.debug("Received Kobo request on a collection unknown to CalibreWeb: " + str(tag_id))
|
||||||
abort(404, description="Collection isn't known to CalibreWeb")
|
abort(404, description="Collection isn't known to CalibreWeb")
|
||||||
|
|
||||||
if not shelf_lib.check_shelf_edit_permissions(shelf):
|
if not shelf_lib.check_shelf_edit_permissions(shelf):
|
||||||
|
log.debug("User is unauthaurized to edit shelf: " + str(tag_id))
|
||||||
abort(401, description="User is unauthaurized to edit shelf.")
|
abort(401, description="User is unauthaurized to edit shelf.")
|
||||||
|
|
||||||
items_unknown_to_calibre = add_items_to_shelf(items, shelf)
|
items_unknown_to_calibre = add_items_to_shelf(items, shelf)
|
||||||
@ -635,13 +640,15 @@ def HandleTagRemoveItem(tag_id):
|
|||||||
abort(400, description="Malformed tags POST request. Data is missing 'Items' field")
|
abort(400, description="Malformed tags POST request. Data is missing 'Items' field")
|
||||||
|
|
||||||
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()
|
or_(ub.Shelf.user_id == current_user.id,
|
||||||
|
ub.Shelf.is_public == 1)).one_or_none()
|
||||||
if not shelf:
|
if not shelf:
|
||||||
log.debug(
|
log.debug(
|
||||||
"Received a request to remove an item from a Collection unknown to CalibreWeb.")
|
"Received a request to remove an item from a Collection unknown to CalibreWeb: " + str(tag_id))
|
||||||
abort(404, description="Collection isn't known to CalibreWeb")
|
abort(404, description="Collection isn't known to CalibreWeb")
|
||||||
|
|
||||||
if not shelf_lib.check_shelf_edit_permissions(shelf):
|
if not shelf_lib.check_shelf_edit_permissions(shelf):
|
||||||
|
log.debug("User is unauthaurized to edit shelf: " + str(tag_id))
|
||||||
abort(401, description="User is unauthaurized to edit shelf.")
|
abort(401, description="User is unauthaurized to edit shelf.")
|
||||||
|
|
||||||
items_unknown_to_calibre = []
|
items_unknown_to_calibre = []
|
||||||
@ -668,7 +675,6 @@ def HandleTagRemoveItem(tag_id):
|
|||||||
|
|
||||||
|
|
||||||
# Add new, changed, or deleted shelves to the sync_results.
|
# Add new, changed, or deleted shelves to the sync_results.
|
||||||
# Note: Public shelves that aren't owned by the user aren't supported.
|
|
||||||
def sync_shelves(sync_token, sync_results, only_kobo_shelves=False):
|
def sync_shelves(sync_token, sync_results, only_kobo_shelves=False):
|
||||||
new_tags_last_modified = sync_token.tags_last_modified
|
new_tags_last_modified = sync_token.tags_last_modified
|
||||||
# transmit all archived shelfs independent of last sync (why should this matter?)
|
# transmit all archived shelfs independent of last sync (why should this matter?)
|
||||||
@ -689,7 +695,7 @@ def sync_shelves(sync_token, sync_results, only_kobo_shelves=False):
|
|||||||
if only_kobo_shelves:
|
if only_kobo_shelves:
|
||||||
for shelf in ub.session.query(ub.Shelf).filter(
|
for shelf in ub.session.query(ub.Shelf).filter(
|
||||||
func.datetime(ub.Shelf.last_modified) > sync_token.tags_last_modified,
|
func.datetime(ub.Shelf.last_modified) > sync_token.tags_last_modified,
|
||||||
ub.Shelf.user_id == current_user.id,
|
or_(ub.Shelf.user_id == current_user.id, ub.Shelf.is_public == 1),
|
||||||
not ub.Shelf.kobo_sync
|
not ub.Shelf.kobo_sync
|
||||||
):
|
):
|
||||||
sync_results.append({
|
sync_results.append({
|
||||||
@ -706,14 +712,14 @@ def sync_shelves(sync_token, sync_results, only_kobo_shelves=False):
|
|||||||
shelflist = ub.session.execute(select(ub.Shelf).outerjoin(ub.BookShelf).filter(
|
shelflist = ub.session.execute(select(ub.Shelf).outerjoin(ub.BookShelf).filter(
|
||||||
or_(func.datetime(ub.Shelf.last_modified) > sync_token.tags_last_modified,
|
or_(func.datetime(ub.Shelf.last_modified) > sync_token.tags_last_modified,
|
||||||
func.datetime(ub.BookShelf.date_added) > sync_token.tags_last_modified),
|
func.datetime(ub.BookShelf.date_added) > sync_token.tags_last_modified),
|
||||||
ub.Shelf.user_id == current_user.id,
|
or_(ub.Shelf.user_id == current_user.id, ub.Shelf.is_public == 1),
|
||||||
*extra_filters
|
*extra_filters
|
||||||
).distinct().order_by(func.datetime(ub.Shelf.last_modified).asc())).columns(ub.Shelf)
|
).distinct().order_by(func.datetime(ub.Shelf.last_modified).asc())).columns(ub.Shelf)
|
||||||
else:
|
else:
|
||||||
shelflist = ub.session.query(ub.Shelf).outerjoin(ub.BookShelf).filter(
|
shelflist = ub.session.query(ub.Shelf).outerjoin(ub.BookShelf).filter(
|
||||||
or_(func.datetime(ub.Shelf.last_modified) > sync_token.tags_last_modified,
|
or_(func.datetime(ub.Shelf.last_modified) > sync_token.tags_last_modified,
|
||||||
func.datetime(ub.BookShelf.date_added) > sync_token.tags_last_modified),
|
func.datetime(ub.BookShelf.date_added) > sync_token.tags_last_modified),
|
||||||
ub.Shelf.user_id == current_user.id,
|
or_(ub.Shelf.user_id == current_user.id, ub.Shelf.is_public == 1),
|
||||||
*extra_filters
|
*extra_filters
|
||||||
).distinct().order_by(func.datetime(ub.Shelf.last_modified).asc())
|
).distinct().order_by(func.datetime(ub.Shelf.last_modified).asc())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user