41fb033d30
- Replace Axum with Chi router - Replace sqlx with pgx for PostgreSQL - Replace tonic/prost with grpc-go - Replace tracing with zerolog - Update flake.nix for Go build with protoc generation - Preserve all existing endpoints and functionality Stack: Chi, pgx, grpc-go, zerolog, yaml.v3
55 lines
1.3 KiB
Go
55 lines
1.3 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("/library", func(r chi.Router) {
|
|
r.Get("/artists", h.ListLibraryArtists)
|
|
r.Get("/albums", h.ListLibraryAlbums)
|
|
r.Get("/stats", h.LibraryStats)
|
|
})
|
|
})
|
|
|
|
return r
|
|
}
|