fix(subsonic): answer what the OpenSubsonic spec and Subsonic apps require

- getOpenSubsonicExtensions answers, without credentials, as the spec
  requires of a server that says openSubsonic=true; it lists
  apiKeyAuthentication. An apiKey sent with u is error 43 and an unknown
  apiKey error 44, the extension's codes; a wrong key still counts toward the
  sign-in throttle.
- search3 with an empty query (or two quote marks) matches everything, paged
  in a stable order, so apps that keep a copy of the library (Symfonium) can
  download it. A page of songs reads its albums and artists in two queries,
  not two per song.
- getAlbumList2 serves type=starred and highest (the listener's liked
  albums) and byYear (oldest first, newest first for a backwards range).
- Internet radio, podcasts, bookmarks, shares, chat and now-playing answer
  with an empty list instead of "Method not implemented", so an app shows an
  empty tab rather than an error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 13:14:31 -05:00
co-authored by Claude Opus 5.5
parent 1efc65ee10
commit cd78529ae8
14 changed files with 575 additions and 50 deletions
+7 -2
View File
@@ -61,7 +61,7 @@ func Middleware(pool *pgxpool.Pool, cfg Config, guard *auth.LoginGuard, hops fun
return
}
user, code, msg := authenticate(r, pool, cfg)
if code == ErrWrongCredentials {
if code == ErrWrongCredentials || code == ErrInvalidAPIKey {
guard.Fail(account, addr)
}
if code != 0 {
@@ -80,10 +80,15 @@ func authenticate(r *http.Request, pool *pgxpool.Pool, cfg Config) (dbq.User, in
params := r.URL.Query()
if apiKey := params.Get("apiKey"); apiKey != "" {
// The apiKeyAuthentication extension forbids a username beside the
// key, so a request can never name one account and prove another.
if params.Has("u") {
return dbq.User{}, ErrConflictingAuth, "Send apiKey without u"
}
user, err := q.GetUserByAPITokenHash(r.Context(), auth.HashAPIToken(apiKey))
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return dbq.User{}, ErrWrongCredentials, "Invalid apiKey"
return dbq.User{}, ErrInvalidAPIKey, "Invalid apiKey"
}
return dbq.User{}, ErrGeneric, "Auth lookup failed"
}