feat: broadcast progress updates from KOReader sync

Add WebSocket broadcast to KOReader progress sync:
- Integrate ConnectionManager into KOReaderHandler
- Broadcast progress updates on successful sync
- Include source device information (model, type)
- Real-time updates to all connected clients

When KOReader devices sync reading progress, all connected
WebSocket clients (web browsers, mobile apps, other devices)
receive instant updates.
This commit is contained in:
2026-01-30 21:48:14 -05:00
parent 4681fb474e
commit 885cbd5d47
+23 -3
View File
@@ -2,6 +2,7 @@ package handlers
import (
"bookmann/internal/database"
wsync "bookmann/internal/sync"
"fmt"
"net/http"
"time"
@@ -12,11 +13,12 @@ import (
)
type KOReaderHandler struct {
db *database.Queries
db *database.Queries
connManager *wsync.ConnectionManager
}
func NewKOReaderHandler(db *database.Queries) *KOReaderHandler {
return &KOReaderHandler{db: db}
func NewKOReaderHandler(db *database.Queries, connManager *wsync.ConnectionManager) *KOReaderHandler {
return &KOReaderHandler{db: db, connManager: connManager}
}
type KOReaderProgressRequest struct {
@@ -274,6 +276,24 @@ func (h *KOReaderHandler) updateProgressForBook(c echo.Context, userID pgtype.UU
LastSyncSource: pgtype.Text{String: "koreader", Valid: true},
})
if err == nil {
// Broadcast progress update to all connected WebSocket clients
deviceInfo := book.DeviceInfo
if deviceInfo.DeviceModel == "" {
deviceInfo.DeviceModel = "KOReader Device"
}
h.connManager.BroadcastProgressUpdate(
uuid.UUID(mediaItemID.Bytes),
book.Percentage,
wsync.SourceDevice{
ID: uuid.UUID(userID.Bytes).String(),
Name: deviceInfo.DeviceModel,
Type: "koreader",
},
)
}
return err
}