fix(subsonic): keep the placeholder for a missing username when Gravatar is off

Parsing username before the EnableGravatar short-circuit turned a request with
no username into Subsonic error 10, where it used to return a 200 placeholder
without touching the DB.
This commit is contained in:
Deluan 2026-09-07 20:56:30 -04:00
commit 41d7d1d48b
2 changed files with 23 additions and 0 deletions

View file

@ -23,6 +23,11 @@ func (api *Router) GetAvatar(w http.ResponseWriter, r *http.Request) (*responses
p := req.Params(r)
username, err := p.String("username")
if err != nil {
// Same reason as the unresolvable-user case below: the old handler short-circuited on
// EnableGravatar before it ever looked at the parameter.
if !conf.Server.EnableGravatar {
return api.getPlaceHolderAvatar(w, r)
}
return nil, err
}
ctx := r.Context()

View file

@ -21,6 +21,7 @@ import (
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/request"
"github.com/navidrome/navidrome/tests"
"github.com/navidrome/navidrome/utils/req"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
@ -262,6 +263,23 @@ var _ = Describe("MediaRetrievalController", func() {
Expect(err).ToNot(HaveOccurred())
Expect(w.Code).To(Equal(http.StatusOK))
})
It("serves the placeholder when the username is missing and Gravatar is off, as before", func() {
conf.Server.EnableGravatar = false
_, err := router.GetAvatar(w, newGetRequest())
Expect(err).ToNot(HaveOccurred())
Expect(w.Code).To(Equal(http.StatusOK))
})
It("returns the same error as before for a missing username when Gravatar is on", func() {
conf.Server.EnableGravatar = true
_, err := router.GetAvatar(w, newGetRequest())
Expect(err).To(MatchError(req.ErrMissingParam))
})
})
Describe("GetLyrics", func() {