mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-08 02:17:25 +02:00
Resolve conflicts with the stateless-repositories refactor (#6149): - port podcast repositories, model interfaces, mocks, service and handlers to per-call ctx - podcast channel repo now implements generic rest.Repository/Persistable - register podcast repos in SQLStore and MockDataStore - merge OpenSubsonic extensions (apiKeyAuthentication + podcast extensions) - renumber podcast migrations after upstream's latest (20260930...)
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package nativeapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/deluan/rest"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/navidrome/navidrome/core/podcasts"
|
|
"github.com/navidrome/navidrome/server"
|
|
)
|
|
|
|
func (api *Router) addPodcastRoute(r chi.Router) {
|
|
repo := api.ds.PodcastChannel()
|
|
r.Route("/podcast", func(r chi.Router) {
|
|
r.Get("/", rest.GetAll(repo))
|
|
r.With(adminOnlyMiddleware).Get("/preview", api.podcastPreview)
|
|
r.Route("/{id}", func(r chi.Router) {
|
|
r.Use(server.URLParamsMiddleware)
|
|
r.Get("/", rest.Get(repo))
|
|
r.Delete("/", rest.Delete(repo))
|
|
})
|
|
})
|
|
}
|
|
|
|
func (api *Router) podcastPreview(w http.ResponseWriter, r *http.Request) {
|
|
feedURL := r.URL.Query().Get("url")
|
|
if feedURL == "" {
|
|
http.Error(w, "url is required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
feed, err := podcasts.ParseFeedPreview(feedURL)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
exists, _ := api.ds.PodcastChannel().ExistsByURL(r.Context(), feedURL)
|
|
feed.AlreadyExists = exists
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(feed)
|
|
}
|