From 051ee287c78e85370536353a1d5f475d333dfd49 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 9 Apr 2026 21:16:53 -0400 Subject: [PATCH] feat(backend): add EPUB CFI and percentage to reading progress Enhance reading progress tracking to support EPUB-specific location data: - Add epubcfi field to store EPUB Canonical Fragment Identifier - Add percentage field for normalized position across formats - Update UpdateReadingProgress API handler to accept new fields - Modify database queries to persist additional progress metadata This enables precise position tracking in reflowable EPUB content where page numbers are insufficient for accurate bookmarking. --- internal/database/queries.sql.go | 2 ++ internal/handlers/media.go | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/database/queries.sql.go b/internal/database/queries.sql.go index f94f988..a70b466 100644 --- a/internal/database/queries.sql.go +++ b/internal/database/queries.sql.go @@ -9579,6 +9579,8 @@ type UpdateReadingProgressParams struct { UserID pgtype.UUID `db:"user_id" json:"user_id"` CurrentPage pgtype.Int4 `db:"current_page" json:"current_page"` TotalPages pgtype.Int4 `db:"total_pages" json:"total_pages"` + Epubcfi string `json:"epubcfi"` + Percentage float64 `json:"percentage"` } func (q *Queries) UpdateReadingProgress(ctx context.Context, arg UpdateReadingProgressParams) (ReadingProgress, error) { diff --git a/internal/handlers/media.go b/internal/handlers/media.go index 25c3b11..536ce30 100644 --- a/internal/handlers/media.go +++ b/internal/handlers/media.go @@ -921,8 +921,10 @@ func (mh *MediaHandler) UpdateMediaReadingProgress(c *echo.Context) error { } var req struct { - CurrentPage int32 `json:"current_page"` - TotalPages int32 `json:"total_pages"` + CurrentPage int32 `json:"current_page"` + TotalPages int32 `json:"total_pages"` + Epubcfi string `json:"epubcfi"` + Percentage float64 `json:"percentage"` } if err := c.Bind(&req); err != nil { return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request"}) @@ -936,6 +938,8 @@ func (mh *MediaHandler) UpdateMediaReadingProgress(c *echo.Context) error { UserID: pgtype.UUID{Bytes: userUUID, Valid: true}, CurrentPage: pgtype.Int4{Int32: req.CurrentPage, Valid: true}, TotalPages: pgtype.Int4{Int32: req.TotalPages, Valid: req.TotalPages > 0}, + Epubcfi: req.Epubcfi, + Percentage: req.Percentage, }) if err != nil { return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})