refactor(handlers): update all handlers for Echo v5 compatibility
Update all handler functions to use *echo.Context (pointer) instead of echo.Context (value) as required by Echo v5. Changes across all handler files: - analytics.go: Update handler signatures - auth.go: Update authentication handler signatures - book_matching.go: Update matching handler signatures - collections.go: Update collection handler signatures - collections_preview_test.go: Update test signatures - commonhandlers.go: Update common handler signatures - conflicts.go: Update conflict handler signatures - context.go: Update context handler signatures - dashboard.go: Update dashboard handler signatures - devices.go: Update device handler signatures - jobs.go: Update job handler signatures - kobo.go: Update Kobo handler signatures - koreader.go: Update Koreader handler signatures - library.go: Update library handler signatures - matching.go: Update matching handler signatures - media.go: Update media handler signatures - opds.go: Update OPDS handler signatures - progress.go: Update progress handler signatures - queue.go: Update queue handler signatures - refresh_token.go: Update token handler signatures - scanner.go: Update scanner handler signatures - sidecar.go: Update sidecar handler signatures - sync.go: Update sync handler signatures - system_settings.go: Update settings handler signatures - websocket.go: Update WebSocket handler signatures All handlers now properly implement Echo v5's pointer-based context pattern. This change is necessary for type safety and compatibility with Echo v5's improved context handling and WebSocket support.
This commit is contained in:
+11
-11
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
)
|
||||
|
||||
type KoboHandler struct {
|
||||
@@ -28,7 +28,7 @@ func NewKoboHandler(db *database.Queries, connManager *wsync.ConnectionManager)
|
||||
|
||||
// mapContentIdToBookhoardUUID maps Kobo ContentId to Bookhoard UUID with multiple fallback strategies
|
||||
// Enhanced Kobo Sync - ContentId Mapping Logic
|
||||
func (h *KoboHandler) mapContentIdToBookhoardUUID(ctx echo.Context, contentId string, deviceID uuid.UUID) (uuid.UUID, error, string) {
|
||||
func (h *KoboHandler) mapContentIdToBookhoardUUID(ctx *echo.Context, contentId string, deviceID uuid.UUID) (uuid.UUID, error, string) {
|
||||
// Step 1: Try direct ContentId lookup in device_catalogs table
|
||||
catalog, err := h.db.GetDeviceCatalogByKoboContentId(ctx.Request().Context(), contentId)
|
||||
if err == nil && catalog.ID.Valid {
|
||||
@@ -82,7 +82,7 @@ func (h *KoboHandler) mapContentIdToBookhoardUUID(ctx echo.Context, contentId st
|
||||
|
||||
// mapBookhoardUUIDToKoboContentId maps Bookhoard UUID to Kobo ContentId
|
||||
// Creates new entry in device_catalogs if not exists
|
||||
func (h *KoboHandler) mapBookhoardUUIDToKoboContentId(c echo.Context, bookhoardUUID uuid.UUID, deviceID uuid.UUID) (string, error) {
|
||||
func (h *KoboHandler) mapBookhoardUUIDToKoboContentId(c *echo.Context, bookhoardUUID uuid.UUID, deviceID uuid.UUID) (string, error) {
|
||||
// Check if catalog entry already exists
|
||||
catalog, err := h.db.GetDeviceCatalogByBookhoardUUID(c.Request().Context(), database.GetDeviceCatalogByBookhoardUUIDParams{
|
||||
DeviceID: pgtype.UUID{Bytes: deviceID, Valid: true},
|
||||
@@ -136,7 +136,7 @@ func (h *KoboHandler) mapBookhoardUUIDToKoboContentId(c echo.Context, bookhoardU
|
||||
}
|
||||
|
||||
// getCollectionMetadataForBook retrieves collection names for a book
|
||||
func (h *KoboHandler) getCollectionMetadataForBook(c echo.Context, bookhoardUUID uuid.UUID, deviceID uuid.UUID) ([]string, error) {
|
||||
func (h *KoboHandler) getCollectionMetadataForBook(c *echo.Context, bookhoardUUID uuid.UUID, deviceID uuid.UUID) ([]string, error) {
|
||||
device := c.Get("device").(database.Devices)
|
||||
pgDeviceID := pgtype.UUID{Bytes: device.ID.Bytes, Valid: true}
|
||||
|
||||
@@ -269,7 +269,7 @@ type KoboAnalyticsTest struct {
|
||||
PercentRead float64 `json:"PercentRead"`
|
||||
}
|
||||
|
||||
func (h *KoboHandler) Initialization(c echo.Context) error {
|
||||
func (h *KoboHandler) Initialization(c *echo.Context) error {
|
||||
device := c.Get("device").(database.Devices)
|
||||
userID := device.UserID.Bytes
|
||||
deviceID := device.ID.Bytes
|
||||
@@ -379,11 +379,11 @@ func (h *KoboHandler) Initialization(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *KoboHandler) LibrarySync(c echo.Context) error {
|
||||
func (h *KoboHandler) LibrarySync(c *echo.Context) error {
|
||||
return h.Initialization(c)
|
||||
}
|
||||
|
||||
func (h *KoboHandler) Markup(c echo.Context) error {
|
||||
func (h *KoboHandler) Markup(c *echo.Context) error {
|
||||
device := c.Get("device").(database.Devices)
|
||||
userID := device.UserID.Bytes
|
||||
deviceID := device.ID.Bytes
|
||||
@@ -521,7 +521,7 @@ func (h *KoboHandler) Markup(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (h *KoboHandler) Bookmark(c echo.Context) error {
|
||||
func (h *KoboHandler) Bookmark(c *echo.Context) error {
|
||||
device := c.Get("device").(database.Devices)
|
||||
userID := device.UserID.Bytes
|
||||
deviceID := device.ID.Bytes
|
||||
@@ -590,7 +590,7 @@ func (h *KoboHandler) Bookmark(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *KoboHandler) AnalyticsGettests(c echo.Context) error {
|
||||
func (h *KoboHandler) AnalyticsGettests(c *echo.Context) error {
|
||||
device := c.Get("device").(database.Devices)
|
||||
userID := device.UserID.Bytes
|
||||
deviceID := device.ID.Bytes
|
||||
@@ -649,7 +649,7 @@ func (h *KoboHandler) AnalyticsGettests(c echo.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
func parseKoboDeviceHeader(c echo.Context) (KoboDeviceInfo, error) {
|
||||
func parseKoboDeviceHeader(c *echo.Context) (KoboDeviceInfo, error) {
|
||||
deviceHeader := c.Request().Header.Get("x-kobo-device")
|
||||
if deviceHeader == "" {
|
||||
return KoboDeviceInfo{}, fmt.Errorf("missing x-kobo-device header")
|
||||
@@ -663,7 +663,7 @@ func parseKoboDeviceHeader(c echo.Context) (KoboDeviceInfo, error) {
|
||||
return device, nil
|
||||
}
|
||||
|
||||
func (h *KoboHandler) SyncFromServer(c echo.Context) error {
|
||||
func (h *KoboHandler) SyncFromServer(c *echo.Context) error {
|
||||
device := c.Get("device").(database.Devices)
|
||||
userID := device.UserID.Bytes
|
||||
deviceID := device.ID.Bytes
|
||||
|
||||
Reference in New Issue
Block a user