Major refactoring milestone - migrate all routes from main.go to internal/router/ package: ## Changes ### cmd/server/main.go - Reduced from 858 lines to 163 lines (81% reduction) - Removed all inline route definitions - Added router.RegisterRoutes() call with full config - Clean separation: setup → router registration → server start ### internal/router/ package Created comprehensive route organization: - router.go: Main router setup and JWT middleware - auth.go: Authentication routes (login, register, profile, etc.) - library.go: Library management routes - device.go: Device registration and management - sync.go: KOReader/Kobo sync + book matching + WebSocket - media.go: Media download, shelves, bulk operations - conflicts.go: Conflict resolution routes - analytics.go: Analytics API routes - queue.go: Sync queue management - opds.go: OPDS feed routes - frontend.go: SSR pages (/login, /admin, /dashboard, etc.) - docs.go: Documentation routes - helpers.go: Template rendering helpers ## Verification ✅ All 26 guideline checks pass ✅ Code compiles successfully ✅ Zero API behavior changes (100% compatible) ✅ Follows Go standard project layout ## Breaking Changes None - API compatibility fully maintained
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package router
|
|
|
|
import (
|
|
"bookhoard/internal/handlers"
|
|
|
|
"github.com/labstack/echo-jwt/v4"
|
|
)
|
|
|
|
func registerMediaRoutes(cfg *Config) {
|
|
e := cfg.Echo
|
|
|
|
// JWT middleware for protected routes
|
|
jwtMiddleware := echojwt.WithConfig(echojwt.Config{
|
|
SigningKey: []byte(cfg.Cfg.JWTSecret),
|
|
ContextKey: "user",
|
|
})
|
|
|
|
protected := e.Group("/api", jwtMiddleware)
|
|
|
|
// Media item handler
|
|
mediaHandler := handlers.NewMediaHandler(cfg.Queries)
|
|
|
|
// Download route (public)
|
|
e.GET("/api/books/:uuid/download", mediaHandler.DownloadBook)
|
|
|
|
// Shelf management (protected)
|
|
protected.POST("/devices/:id/shelves", mediaHandler.AddToShelf)
|
|
protected.GET("/devices/:id/shelves", mediaHandler.GetShelf)
|
|
protected.DELETE("/devices/:id/shelves", mediaHandler.RemoveFromShelf)
|
|
protected.DELETE("/devices/:id/shelves/clear", mediaHandler.ClearShelf)
|
|
|
|
// Bulk book operations (protected)
|
|
books := protected.Group("/books")
|
|
books.POST("/bulk-delete", mediaHandler.HandleBulkDelete)
|
|
books.POST("/bulk-update", mediaHandler.HandleBulkUpdate)
|
|
}
|