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