mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-18 16:18:52 +01:00
Registered unauthenticated (matching real Jellyfin's login-picker use case), but narrowed to conf.Server.Jellyfin.ExposedPublicUsers for anonymous callers. Also fills PrimaryImageTag on userToDto and getPublicUsers.
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
package jellyfin
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/navidrome/navidrome/log"
|
|
"github.com/navidrome/navidrome/model/request"
|
|
"github.com/navidrome/navidrome/server/jellyfin/dto"
|
|
)
|
|
|
|
// getUserViews returns one CollectionFolder view per accessible library, so clients browse each
|
|
// library as its own top-level view rather than one aggregate.
|
|
func (api *Router) getUserViews(w http.ResponseWriter, r *http.Request) {
|
|
u, _ := request.UserFrom(r.Context())
|
|
views := make([]dto.BaseItemDto, 0, len(u.Libraries))
|
|
for _, lib := range u.Libraries {
|
|
views = append(views, libraryView(lib))
|
|
}
|
|
api.ok(w, r, dto.QueryResult{Items: views, TotalRecordCount: len(views), StartIndex: 0})
|
|
}
|
|
|
|
func (api *Router) getCurrentUser(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
u, _ := request.UserFrom(ctx)
|
|
api.ok(w, r, userToDto(&u, api.serverName(), api.serverID(ctx)))
|
|
}
|
|
|
|
// getPublicUsers advertises the users named in Jellyfin.ExposedPublicUsers for a client login
|
|
// picker. The route is unauthenticated, so it lists only the configured allowlist (never the full
|
|
// user table) and returns a minimal DTO — no Policy/Configuration, which would leak admin status.
|
|
func (api *Router) getPublicUsers(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
serverID := api.serverID(ctx)
|
|
seen := make(map[string]bool)
|
|
users := []dto.UserDto{}
|
|
for _, name := range publicUsernames() {
|
|
key := strings.ToLower(name)
|
|
if seen[key] {
|
|
continue
|
|
}
|
|
seen[key] = true
|
|
usr, err := api.ds.User(ctx).FindByUsername(name)
|
|
if err != nil {
|
|
log.Warn(ctx, "Jellyfin API: configured public user not found", "username", name, err)
|
|
continue
|
|
}
|
|
users = append(users, dto.UserDto{
|
|
Name: usr.UserName,
|
|
Id: dto.EncodeID(usr.ID),
|
|
ServerId: serverID,
|
|
HasPassword: true,
|
|
PrimaryImageTag: usr.AvatarTag(),
|
|
})
|
|
}
|
|
api.ok(w, r, users)
|
|
}
|