fix(subsonic): a scrobble of an unknown song answers not found (70) (#8125)
release / web (push) Successful in 1m20s
release / go (push) Successful in 1m49s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m3s
release / android (push) Successful in 4m26s
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 / Build signed APK (push) Canceled after 4m43s
release / web (push) Successful in 1m20s
release / go (push) Successful in 1m49s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m3s
release / android (push) Successful in 4m26s
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 / Build signed APK (push) Canceled after 4m43s
A scrobble whose id named no track reached the play writer and came back as a generic failure (0). The handler now looks the song up first, as stream does, and answers 70 with nothing recorded; a lookup that fails for another reason is still a generic error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
@@ -125,3 +126,24 @@ func TestHandleScrobble_AWildClockIsBoundedToNow(t *testing.T) {
|
||||
t.Fatalf("play dated %v, want no later than now", startedAt)
|
||||
}
|
||||
}
|
||||
|
||||
// A scrobble of a song the library doesn't hold answers "not found" (70),
|
||||
// as stream and getSong do, and records nothing.
|
||||
func TestHandleScrobble_AnUnknownSongIsNotFound(t *testing.T) {
|
||||
pool, user, _ := testScrobblePool(t)
|
||||
m := newScrobbleHandlers(pool)
|
||||
unknown := uuidToID(pgtype.UUID{Bytes: [16]byte{0xee}, Valid: true})
|
||||
|
||||
for _, submission := range []string{"true", "false"} {
|
||||
if code := call(t, m.handleScrobble, user, "id="+unknown+"&submission="+submission, nil); code != ErrDataNotFound {
|
||||
t.Errorf("submission=%s: error %d, want %d", submission, code, ErrDataNotFound)
|
||||
}
|
||||
}
|
||||
var n int
|
||||
if err := pool.QueryRow(context.Background(), "SELECT count(*) FROM play_events WHERE user_id=$1", user.ID).Scan(&n); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 0 {
|
||||
t.Errorf("play_events = %d, want none", n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,8 +200,19 @@ func (m *mediaHandlers) handleScrobble(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
at = playevents.ClampClientTime(at, user.CreatedAt.Time, time.Now().UTC())
|
||||
}
|
||||
q := dbq.New(m.pool)
|
||||
// A song the library doesn't hold is "not found" (70), as stream and
|
||||
// getSong answer it, not a failure to record.
|
||||
if _, err := q.GetTrackByID(r.Context(), trackID); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
WriteFail(w, r, ErrDataNotFound, "Track not found")
|
||||
return
|
||||
}
|
||||
WriteFail(w, r, ErrGeneric, "Failed to load track")
|
||||
return
|
||||
}
|
||||
clientID := params.Get("c")
|
||||
source, err := m.recall.sourceFor(r.Context(), dbq.New(m.pool), user.ID, clientID, trackID)
|
||||
source, err := m.recall.sourceFor(r.Context(), q, user.ID, clientID, trackID)
|
||||
if err != nil {
|
||||
// Crediting a mix is a refinement; the play itself still counts.
|
||||
m.logger.Warn("subsonic: scrobble mix lookup failed", "err", err)
|
||||
|
||||
Reference in New Issue
Block a user