navidrome/server/nativeapi/podcasts.go
Jiho Andrew Lee 19385dc28b Merge upstream/master into feat-podcast-ux-improvements/5420
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...)
2026-09-30 15:23:00 +09:00

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)
}