feat(subsonic): add avatar support

closes: #228
This commit is contained in:
Brian Doherty
2022-07-20 23:16:13 +01:00
committed by sentriz
parent 7ab378accb
commit 5e66261f0c
15 changed files with 288 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
package ctrlsubsonic
import (
"bytes"
"errors"
"fmt"
"log"
@@ -297,3 +298,18 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
}
return nil
}
func (c *Controller) ServeGetAvatar(w http.ResponseWriter, r *http.Request) *spec.Response {
params := r.Context().Value(CtxParams).(params.Params)
user := r.Context().Value(CtxUser).(*db.User)
username, err := params.Get("username")
if err != nil {
return spec.NewError(10, "please provide an `username` parameter")
}
reqUser := c.DB.GetUserByName(username)
if (user != reqUser) && !user.IsAdmin {
return spec.NewError(50, "user not admin")
}
http.ServeContent(w, r, "", time.Now(), bytes.NewReader(reqUser.Avatar))
return nil
}