feat(subsonic): scan status, artist and album info, lyrics, ratings and users
release / go (push) Failing after 1m15s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 3m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m33s
release / Build signed APK (push) Canceled after 4m9s
release / go (push) Failing after 1m15s
release / web (push) Successful in 1m18s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 3m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 4m33s
release / Build signed APK (push) Canceled after 4m9s
The last Subsonic methods apps call that Minstrel didn't answer: - getScanStatus counts the songs whose files are present and says whether a scan is running; startScan, for an admin, starts the scan the web app's Rescan starts, and answers "scanning" straight away since the scan records itself a moment later. - getArtistInfo and getArtistInfo2 give the artist's MusicBrainz id and the artists in this library that sound like them, from an artist, album or song id; getAlbumInfo and getAlbumInfo2 give the album's MusicBrainz id. Minstrel fetches no biographies or outside images, so none are sent. - getLyrics (by artist and title) and getLyricsBySongId (OpenSubsonic songLyrics, now declared) read lyrics when asked: a .lrc file beside the song gives timed lyrics, otherwise the song's own lyrics tag. - setRating accepts a rating and keeps none: a like is Minstrel's only rating, and a low rating is never read as a dislike. - getUsers lists every user, for an admin only. ArtistRef no longer fixes its XML element name, so it can appear as similarArtist; every field holding it names the element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,10 +42,46 @@ type User struct {
|
||||
VideoConversionRole bool `json:"videoConversionRole" xml:"videoConversionRole,attr"`
|
||||
}
|
||||
|
||||
// userHandlers serves getUser. lookup finds a user by exact username; it is
|
||||
// a field so tests can answer without a database.
|
||||
// userHandlers serves getUser and getUsers. lookup finds a user by exact
|
||||
// username and list lists every user; they are fields so tests can answer
|
||||
// without a database.
|
||||
type userHandlers struct {
|
||||
lookup func(ctx context.Context, username string) (dbq.User, error)
|
||||
list func(ctx context.Context) ([]dbq.ListUsersRow, error)
|
||||
}
|
||||
|
||||
// UsersResponse is the body of getUsers.
|
||||
type UsersResponse struct {
|
||||
Envelope
|
||||
Users UsersContainer `json:"users" xml:"users"`
|
||||
}
|
||||
|
||||
type UsersContainer struct {
|
||||
Users []User `json:"user" xml:"user"`
|
||||
}
|
||||
|
||||
// getUsers lists every user, for an admin only; anyone else gets
|
||||
// ErrNotAuthorized, as the spec has it.
|
||||
func (h *userHandlers) getUsers(w http.ResponseWriter, r *http.Request) {
|
||||
caller, ok := UserFromContext(r.Context())
|
||||
if !ok {
|
||||
WriteFail(w, r, ErrNotAuthorized, "Not authenticated")
|
||||
return
|
||||
}
|
||||
if !caller.IsAdmin {
|
||||
WriteFail(w, r, ErrNotAuthorized, "Only an admin can list users")
|
||||
return
|
||||
}
|
||||
rows, err := h.list(r.Context())
|
||||
if err != nil {
|
||||
WriteFail(w, r, ErrGeneric, "Failed to list users")
|
||||
return
|
||||
}
|
||||
users := make([]User, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
users = append(users, rolePayload(row.Username, row.IsAdmin))
|
||||
}
|
||||
Write(w, r, UsersResponse{Envelope: NewEnvelope("ok"), Users: UsersContainer{Users: users}})
|
||||
}
|
||||
|
||||
// getUser returns the authenticated user when no username is provided or
|
||||
@@ -79,12 +115,15 @@ func (h *userHandlers) getUser(w http.ResponseWriter, r *http.Request) {
|
||||
Write(w, r, UserResponse{Envelope: NewEnvelope("ok"), User: userPayload(target)})
|
||||
}
|
||||
|
||||
func userPayload(u dbq.User) User {
|
||||
func userPayload(u dbq.User) User { return rolePayload(u.Username, u.IsAdmin) }
|
||||
|
||||
// rolePayload is the role bag for a user with this name and admin flag.
|
||||
func rolePayload(username string, admin bool) User {
|
||||
return User{
|
||||
Username: u.Username,
|
||||
Username: username,
|
||||
ScrobblingEnabled: true,
|
||||
AdminRole: u.IsAdmin,
|
||||
SettingsRole: u.IsAdmin,
|
||||
AdminRole: admin,
|
||||
SettingsRole: admin,
|
||||
DownloadRole: true,
|
||||
UploadRole: false,
|
||||
PlaylistRole: true,
|
||||
|
||||
Reference in New Issue
Block a user