mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-16 04:00:38 +03:00
GetCoverArt returns placeholder if id
is missing
This mimics Subsonic behaviour, even if it contradicts the API documentation, which states `id` is required Fixes #1139
This commit is contained in:
parent
7bbb09e546
commit
91a91f7e06
@ -58,10 +58,7 @@ func (c *MediaRetrievalController) getPlaceHolderAvatar(w http.ResponseWriter, r
|
||||
}
|
||||
|
||||
func (c *MediaRetrievalController) GetCoverArt(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||
id, err := requiredParamString(r, "id")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id := utils.ParamStringDefault(r, "id", "non-existent")
|
||||
size := utils.ParamInt(r, "size", 0)
|
||||
|
||||
w.Header().Set("cache-control", "public, max-age=315360000")
|
||||
|
@ -37,11 +37,12 @@ var _ = Describe("MediaRetrievalController", func() {
|
||||
Expect(w.Body.String()).To(Equal(artwork.data))
|
||||
})
|
||||
|
||||
It("should fail if missing id parameter", func() {
|
||||
It("should return placeholder if id parameter is missing (mimicking Subsonic)", func() {
|
||||
r := newGetRequest()
|
||||
_, err := controller.GetCoverArt(w, r)
|
||||
|
||||
Expect(err).To(MatchError("required 'id' parameter is missing"))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(w.Body.String()).To(Equal(artwork.data))
|
||||
})
|
||||
|
||||
It("should fail when the file is not found", func() {
|
||||
|
@ -11,6 +11,14 @@ func ParamString(r *http.Request, param string) string {
|
||||
return r.URL.Query().Get(param)
|
||||
}
|
||||
|
||||
func ParamStringDefault(r *http.Request, param, def string) string {
|
||||
v := ParamString(r, param)
|
||||
if v == "" {
|
||||
return def
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func ParamStrings(r *http.Request, param string) []string {
|
||||
return r.URL.Query()[param]
|
||||
}
|
||||
|
@ -27,6 +27,20 @@ var _ = Describe("Request Helpers", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ParamStringDefault", func() {
|
||||
BeforeEach(func() {
|
||||
r = httptest.NewRequest("GET", "/ping?a=123", nil)
|
||||
})
|
||||
|
||||
It("returns default string if param does not exist", func() {
|
||||
Expect(ParamStringDefault(r, "xx", "default_value")).To(Equal("default_value"))
|
||||
})
|
||||
|
||||
It("returns param as string", func() {
|
||||
Expect(ParamStringDefault(r, "a", "default_value")).To(Equal("123"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("ParamStrings", func() {
|
||||
BeforeEach(func() {
|
||||
r = httptest.NewRequest("GET", "/ping?a=123&a=456", nil)
|
||||
|
Loading…
x
Reference in New Issue
Block a user