86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
"github.com/go-chi/cors"
|
|
)
|
|
|
|
func NewRouter(h *Handlers) *chi.Mux {
|
|
r := chi.NewRouter()
|
|
|
|
r.Use(middleware.Logger)
|
|
r.Use(middleware.Recoverer)
|
|
r.Use(cors.Handler(cors.Options{
|
|
AllowedOrigins: []string{"*"},
|
|
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
|
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"},
|
|
AllowCredentials: true,
|
|
MaxAge: 300,
|
|
}))
|
|
|
|
r.Get("/health", h.Health)
|
|
|
|
r.Route("/api", func(r chi.Router) {
|
|
r.Route("/indexers", func(r chi.Router) {
|
|
r.Get("/", h.ListIndexers)
|
|
r.Post("/search", h.SearchIndexers)
|
|
})
|
|
|
|
r.Route("/torrents", func(r chi.Router) {
|
|
r.Get("/", h.ListTorrents)
|
|
r.Post("/", h.AddTorrent)
|
|
r.Get("/{hash}", h.GetTorrent)
|
|
r.Delete("/{hash}", h.RemoveTorrent)
|
|
r.Post("/{hash}/pause", h.PauseTorrent)
|
|
r.Post("/{hash}/resume", h.ResumeTorrent)
|
|
})
|
|
|
|
r.Route("/metadata", func(r chi.Router) {
|
|
r.Post("/artists/search", h.SearchArtists)
|
|
r.Get("/artists/{id}/albums", h.GetArtistAlbums)
|
|
})
|
|
|
|
r.Post("/sync", h.Sync)
|
|
|
|
r.Route("/artists", func(r chi.Router) {
|
|
r.Get("/{id}", h.GetArtist)
|
|
r.Put("/{id}", h.EditArtist)
|
|
r.Post("/{id}/refresh", h.RefreshArtist)
|
|
r.Delete("/{id}", h.DeleteArtist)
|
|
r.Put("/{id}/albums/monitor", h.BulkMonitorArtistAlbums)
|
|
r.Post("/{id}/search", h.SearchArtistAlbums)
|
|
})
|
|
|
|
r.Route("/albums", func(r chi.Router) {
|
|
r.Get("/{id}", h.GetAlbum)
|
|
r.Put("/{id}", h.EditAlbum)
|
|
r.Post("/{id}/search", h.SearchAlbum)
|
|
})
|
|
|
|
r.Post("/blocklist", h.AddToBlocklist)
|
|
|
|
r.Route("/queue", func(r chi.Router) {
|
|
r.Get("/", h.ListQueue)
|
|
r.Post("/", h.AddToQueue)
|
|
r.Post("/sync", h.SyncQueue)
|
|
r.Get("/stats", h.QueueStats)
|
|
r.Get("/{id}", h.GetQueueItem)
|
|
r.Put("/{id}", h.UpdateQueueItem)
|
|
r.Delete("/{id}", h.DeleteQueueItem)
|
|
r.Post("/{id}/blocklist", h.BlocklistQueueItem)
|
|
r.Post("/{id}/import", h.ImportQueueItem)
|
|
})
|
|
|
|
r.Route("/library", func(r chi.Router) {
|
|
r.Get("/artists", h.ListLibraryArtists)
|
|
r.Get("/albums", h.ListLibraryAlbums)
|
|
r.Get("/stats", h.LibraryStats)
|
|
})
|
|
|
|
r.Get("/job/{id}", h.GetJobStatus)
|
|
})
|
|
|
|
return r
|
|
}
|