feat(subsonic): getOpenSubsonicExtensions is now public

This commit is contained in:
Deluan
2024-10-21 16:31:56 -04:00
parent 8808eaddda
commit 23bebe4e06
2 changed files with 177 additions and 128 deletions
+14 -9
View File
@@ -68,12 +68,16 @@ func New(ds model.DataStore, artwork artwork.Artwork, streamer core.MediaStreame
func (api *Router) routes() http.Handler { func (api *Router) routes() http.Handler {
r := chi.NewRouter() r := chi.NewRouter()
r.Use(postFormToQueryParams) r.Use(postFormToQueryParams)
// Public
h(r, "getOpenSubsonicExtensions", api.GetOpenSubsonicExtensions)
// Protected
r.Group(func(r chi.Router) {
r.Use(checkRequiredParameters) r.Use(checkRequiredParameters)
r.Use(authenticate(api.ds)) r.Use(authenticate(api.ds))
r.Use(server.UpdateLastAccessMiddleware(api.ds)) r.Use(server.UpdateLastAccessMiddleware(api.ds))
// TODO Validate API version?
// Subsonic endpoints, grouped by controller // Subsonic endpoints, grouped by controller
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
@@ -138,17 +142,22 @@ func (api *Router) routes() http.Handler {
h(r, "search3", api.Search3) h(r, "search3", api.Search3)
}) })
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(getPlayer(api.players))
h(r, "getUser", api.GetUser) h(r, "getUser", api.GetUser)
h(r, "getUsers", api.GetUsers) h(r, "getUsers", api.GetUsers)
}) })
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(getPlayer(api.players))
h(r, "getScanStatus", api.GetScanStatus) h(r, "getScanStatus", api.GetScanStatus)
h(r, "startScan", api.StartScan) h(r, "startScan", api.StartScan)
}) })
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(getPlayer(api.players))
hr(r, "getAvatar", api.GetAvatar) hr(r, "getAvatar", api.GetAvatar)
h(r, "getLyrics", api.GetLyrics) h(r, "getLyrics", api.GetLyrics)
h(r, "getLyricsBySongId", api.GetLyricsBySongId) h(r, "getLyricsBySongId", api.GetLyricsBySongId)
hr(r, "stream", api.Stream)
hr(r, "download", api.Download)
}) })
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
// configure request throttling // configure request throttling
@@ -163,10 +172,6 @@ func (api *Router) routes() http.Handler {
}) })
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(getPlayer(api.players)) r.Use(getPlayer(api.players))
hr(r, "stream", api.Stream)
hr(r, "download", api.Download)
})
r.Group(func(r chi.Router) {
h(r, "createInternetRadioStation", api.CreateInternetRadio) h(r, "createInternetRadioStation", api.CreateInternetRadio)
h(r, "deleteInternetRadioStation", api.DeleteInternetRadio) h(r, "deleteInternetRadioStation", api.DeleteInternetRadio)
h(r, "getInternetRadioStations", api.GetInternetRadios) h(r, "getInternetRadioStations", api.GetInternetRadios)
@@ -174,6 +179,7 @@ func (api *Router) routes() http.Handler {
}) })
if conf.Server.EnableSharing { if conf.Server.EnableSharing {
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(getPlayer(api.players))
h(r, "getShares", api.GetShares) h(r, "getShares", api.GetShares)
h(r, "createShare", api.CreateShare) h(r, "createShare", api.CreateShare)
h(r, "updateShare", api.UpdateShare) h(r, "updateShare", api.UpdateShare)
@@ -182,12 +188,10 @@ func (api *Router) routes() http.Handler {
} else { } else {
h501(r, "getShares", "createShare", "updateShare", "deleteShare") h501(r, "getShares", "createShare", "updateShare", "deleteShare")
} }
r.Group(func(r chi.Router) {
h(r, "getOpenSubsonicExtensions", api.GetOpenSubsonicExtensions)
})
if conf.Server.Jukebox.Enabled { if conf.Server.Jukebox.Enabled {
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(getPlayer(api.players))
h(r, "jukeboxControl", api.JukeboxControl) h(r, "jukeboxControl", api.JukeboxControl)
}) })
} else { } else {
@@ -203,6 +207,7 @@ func (api *Router) routes() http.Handler {
h410(r, "search") h410(r, "search")
h410(r, "getChatMessages", "addChatMessage") h410(r, "getChatMessages", "addChatMessage")
h410(r, "getVideos", "getVideoInfo", "getCaptions", "hls") h410(r, "getVideos", "getVideoInfo", "getCaptions", "hls")
})
return r return r
} }
+44
View File
@@ -0,0 +1,44 @@
package subsonic_test
import (
"encoding/json"
"net/http"
"net/http/httptest"
"github.com/navidrome/navidrome/server/subsonic"
"github.com/navidrome/navidrome/server/subsonic/responses"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("GetOpenSubsonicExtensions", func() {
var (
router *subsonic.Router
w *httptest.ResponseRecorder
r *http.Request
)
BeforeEach(func() {
router = subsonic.New(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
w = httptest.NewRecorder()
r = httptest.NewRequest("GET", "/getOpenSubsonicExtensions?f=json", nil)
})
It("should return the correct OpenSubsonicExtensions", func() {
router.ServeHTTP(w, r)
// Make sure the endpoint is public, by not passing any authentication
Expect(w.Code).To(Equal(http.StatusOK))
Expect(w.Header().Get("Content-Type")).To(Equal("application/json"))
var response responses.JsonWrapper
err := json.Unmarshal(w.Body.Bytes(), &response)
Expect(err).NotTo(HaveOccurred())
Expect(*response.Subsonic.OpenSubsonicExtensions).To(SatisfyAll(
HaveLen(3),
ContainElement(responses.OpenSubsonicExtension{Name: "transcodeOffset", Versions: []int32{1}}),
ContainElement(responses.OpenSubsonicExtension{Name: "formPost", Versions: []int32{1}}),
ContainElement(responses.OpenSubsonicExtension{Name: "songLyrics", Versions: []int32{1}}),
))
})
})