2020-01-19 14:21:44 -09:00
|
|
|
package subsonic
|
2016-03-03 14:44:39 -09:00
|
|
|
|
2020-01-07 10:56:26 -09:00
|
|
|
import (
|
|
|
|
|
"net/http"
|
2016-03-03 14:44:39 -09:00
|
|
|
|
2023-01-23 19:53:04 -09:00
|
|
|
"github.com/navidrome/navidrome/conf"
|
2020-10-27 14:19:56 -08:00
|
|
|
"github.com/navidrome/navidrome/model/request"
|
2020-01-23 15:44:08 -09:00
|
|
|
"github.com/navidrome/navidrome/server/subsonic/responses"
|
2020-01-07 10:56:26 -09:00
|
|
|
)
|
|
|
|
|
|
2016-03-07 10:13:01 -09:00
|
|
|
// TODO This is a placeholder. The real one has to read this info from a config file or the database
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetUser(r *http.Request) (*responses.Subsonic, error) {
|
2020-10-27 14:19:56 -08:00
|
|
|
loggedUser, ok := request.UserFrom(r.Context())
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, newError(responses.ErrorGeneric, "Internal error")
|
2020-01-07 10:56:26 -09:00
|
|
|
}
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2020-01-07 10:56:26 -09:00
|
|
|
response.User = &responses.User{}
|
2020-10-27 14:19:56 -08:00
|
|
|
response.User.Username = loggedUser.UserName
|
|
|
|
|
response.User.AdminRole = loggedUser.IsAdmin
|
|
|
|
|
response.User.Email = loggedUser.Email
|
2020-01-07 10:56:26 -09:00
|
|
|
response.User.StreamRole = true
|
|
|
|
|
response.User.ScrobblingEnabled = true
|
2023-01-23 19:53:04 -09:00
|
|
|
response.User.DownloadRole = conf.Server.EnableDownloads
|
2023-01-29 16:33:10 -09:00
|
|
|
response.User.ShareRole = conf.Server.EnableSharing
|
2023-09-14 16:15:20 -08:00
|
|
|
response.User.JukeboxRole = conf.Server.Jukebox.Enabled
|
2020-01-07 10:56:26 -09:00
|
|
|
return response, nil
|
2016-03-03 14:44:39 -09:00
|
|
|
}
|
2020-10-27 14:19:56 -08:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetUsers(r *http.Request) (*responses.Subsonic, error) {
|
2020-10-27 14:19:56 -08:00
|
|
|
loggedUser, ok := request.UserFrom(r.Context())
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, newError(responses.ErrorGeneric, "Internal error")
|
|
|
|
|
}
|
|
|
|
|
user := responses.User{}
|
|
|
|
|
user.Username = loggedUser.Name
|
|
|
|
|
user.AdminRole = loggedUser.IsAdmin
|
|
|
|
|
user.Email = loggedUser.Email
|
|
|
|
|
user.StreamRole = true
|
|
|
|
|
user.ScrobblingEnabled = true
|
2023-01-23 19:53:04 -09:00
|
|
|
user.DownloadRole = conf.Server.EnableDownloads
|
2023-01-29 16:33:10 -09:00
|
|
|
user.ShareRole = conf.Server.EnableSharing
|
2023-09-14 16:15:20 -08:00
|
|
|
user.JukeboxRole = conf.Server.Jukebox.Enabled
|
2020-10-27 14:19:56 -08:00
|
|
|
response := newResponse()
|
|
|
|
|
response.Users = &responses.Users{User: []responses.User{user}}
|
|
|
|
|
return response, nil
|
|
|
|
|
}
|