feat: integrate ConnectionManager into Handler struct
Add WebSocket ConnectionManager to Handler: - Add connManager field to Handler struct - Update NewHandler to accept ConnectionManager parameter - Update SetupRoutes to pass ConnectionManager through - Import sync package with alias to avoid conflicts This enables progress handlers to broadcast updates via WebSocket.
This commit is contained in:
@@ -2,7 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"bookmann/internal/database"
|
||||
"bookmann/internal/sync"
|
||||
wsync "bookmann/internal/sync"
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
@@ -118,7 +118,7 @@ func (h *Handler) UpdateUniversalProgress(c echo.Context) error {
|
||||
if req.Location.Percentage != nil {
|
||||
percentage = *req.Location.Percentage
|
||||
} else if req.Location.Page != nil && req.Location.TotalPages != nil {
|
||||
percentage = sync.PageToPercentage(*req.Location.Page, *req.Location.TotalPages)
|
||||
percentage = wsync.PageToPercentage(*req.Location.Page, *req.Location.TotalPages)
|
||||
}
|
||||
|
||||
currentPage := 0
|
||||
@@ -171,6 +171,20 @@ func (h *Handler) UpdateUniversalProgress(c echo.Context) error {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "failed to update progress")
|
||||
}
|
||||
|
||||
// Broadcast progress update to all connected WebSocket clients
|
||||
deviceName := "Web"
|
||||
deviceType := "web"
|
||||
if req.DeviceMetadata.DeviceType != "" {
|
||||
deviceType = req.DeviceMetadata.DeviceType
|
||||
deviceName = req.DeviceMetadata.DeviceType
|
||||
}
|
||||
|
||||
h.connManager.BroadcastProgressUpdate(mediaItemID, percentage, wsync.SourceDevice{
|
||||
ID: uuid.UUID(user.ID.Bytes).String(),
|
||||
Name: deviceName,
|
||||
Type: deviceType,
|
||||
})
|
||||
|
||||
return c.JSON(http.StatusOK, map[string]interface{}{
|
||||
"sync_status": "success",
|
||||
"progress_updated": true,
|
||||
|
||||
Reference in New Issue
Block a user