feat: implement relative path storage and URL resolution for media files
- Add libraryService dependency to CollectionHandler and OPDSHandler for centralized path resolution - Create internal/utils/mediaurl.go with ResolveMediaURL() function as single source of truth - Update GetMediaItem and ListMediaItems handlers to return resolved URLs in API responses - Update collection handlers (GetCollection, TestRules, PreviewCollection) to use resolved cover URLs - Update progress handler (GetAllProgress) to use resolved cover URLs - Add library_id to GetCollectionItems SQL query to enable URL resolution - Refactor media scanner to store relative paths instead of absolute filesystem paths - Add ResolveMediaPath() to LibraryService for resolving relative paths to absolute paths - Add ServeFile endpoint at /uploads/library-:id/* for authenticated file serving - Add MimeTypes map to library_service.go for consistent MIME type handling - Update DownloadBook handler to use resolved filesystem paths - Add getRelativePath() helper to MediaScanner for converting absolute to relative paths - Use strings.EqualFold for case-insensitive path comparisons in zip extraction This change enables the application to work with relative paths stored in the database, making it portable across different server environments while maintaining backward compatibility with existing absolute paths.
This commit is contained in:
@@ -47,9 +47,6 @@ func registerMediaRoutes(cfg *Config) {
|
||||
admin.PUT("/media-items/:id", cfg.MediaHandler.UpdateMediaItem)
|
||||
admin.DELETE("/media-items/:id", cfg.MediaHandler.DeleteMediaItem)
|
||||
|
||||
// Download route (public)
|
||||
e.GET("/api/media-items/:uuid/download", cfg.MediaHandler.DownloadBook)
|
||||
|
||||
// Shelf management (protected)
|
||||
protected.POST("/devices/:id/shelves", cfg.MediaHandler.AddToShelf)
|
||||
protected.GET("/devices/:id/shelves", cfg.MediaHandler.GetShelf)
|
||||
@@ -60,4 +57,10 @@ func registerMediaRoutes(cfg *Config) {
|
||||
mediaItems := protected.Group("/media-items")
|
||||
mediaItems.POST("/bulk-delete", cfg.MediaHandler.HandleBulkDelete)
|
||||
mediaItems.POST("/bulk-update", cfg.MediaHandler.HandleBulkUpdate)
|
||||
|
||||
// File serving - authenticated (registered on Echo to avoid /api prefix)
|
||||
// Create a group with JWT middleware for routes outside /api
|
||||
authenticated := e.Group("", createJWTMiddleware(cfg))
|
||||
// Note: Must be registered LAST as it's a wildcard route
|
||||
authenticated.GET("/uploads/library-:id/*", cfg.MediaHandler.ServeFile)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user