@@ -494,61 +494,9 @@ def handle_annotations(entitlement_id):
494494 GET: Retrieve all annotations for a book
495495 PATCH: Update/create annotations
496496 """
497- if request .method == "GET" :
498- try :
499- data = request .get_json ()
500- log_annotation_data (entitlement_id , "GET" )
501-
502- # Get book from database
503- book = get_book_by_entitlement_id (entitlement_id )
504- if not book :
505- log .warning (f"Book not found for entitlement { entitlement_id } , skipping Hardcover sync" )
506-
507- else :
508- identifiers = get_book_identifiers (book )
509-
510- # Extract annotations
511- if data and "annotations" in data :
512- annotations = data ['annotations' ]
513- log .info (f"Processing { len (annotations )} annotations" )
514-
515- # Batch load existing sync records to avoid N+1 queries
516- existing_syncs = {}
517- annotation_ids = [a .get ('id' ) for a in annotations if a .get ('id' )]
518- if annotation_ids :
519- syncs = ub .session .query (ub .KoboAnnotationSync ).filter (
520- ub .KoboAnnotationSync .annotation_id .in_ (annotation_ids ),
521- ub .KoboAnnotationSync .user_id == current_user .id
522- ).all ()
523- existing_syncs = {s .annotation_id : s for s in syncs }
524-
525- # Check blacklist once per book
526- book_blacklist = ub .session .query (ub .HardcoverBookBlacklist ).filter (
527- ub .HardcoverBookBlacklist .book_id == book .id
528- ).first ()
529- is_blacklisted = book_blacklist and book_blacklist .blacklist_annotations
530-
531- # Initialize progress calculator once per book
532- progress_calculator = EpubProgressCalculator (book )
533-
534- for annotation in annotations :
535- process_annotation_for_sync (
536- annotation = annotation ,
537- book = book ,
538- identifiers = identifiers ,
539- existing_syncs = existing_syncs ,
540- progress_calculator = progress_calculator ,
541- is_blacklisted = is_blacklisted
542- )
543- except requests .exceptions .RequestException as e :
544- log .error (f"Failed to proxy GET annotations to Kobo Reading Services: { e } " )
545- return make_response (jsonify ({"error" : "Failed to proxy request" }), 502 )
546- except Exception as e :
547- log .error (f"Unexpected error proxying GET annotations: { e } " )
548- import traceback
549- log .error (traceback .format_exc ())
550- return make_response (jsonify ({"error" : "Internal server error" }), 500 )
551- elif request .method == "PATCH" :
497+ # GET requests are proxied directly to Kobo at the end of the function
498+ # We only intercept PATCH requests to sync changes to Hardcover
499+ if request .method == "PATCH" :
552500 try :
553501 data = request .get_json ()
554502 log_annotation_data (entitlement_id , "PATCH" , data )
0 commit comments