The first public release of Fabled Minstrel #158

Merged
bvandeusen merged 256 commits from dev into main 2026-12-03 21:41:58 -05:00
2 changed files with 34 additions and 1 deletions
Showing only changes of commit 1c4307e6ef - Show all commits
+22
View File
@@ -11,6 +11,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq" "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) 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)
}
}
+12 -1
View File
@@ -200,8 +200,19 @@ func (m *mediaHandlers) handleScrobble(w http.ResponseWriter, r *http.Request) {
} }
at = playevents.ClampClientTime(at, user.CreatedAt.Time, time.Now().UTC()) 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") 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 { if err != nil {
// Crediting a mix is a refinement; the play itself still counts. // Crediting a mix is a refinement; the play itself still counts.
m.logger.Warn("subsonic: scrobble mix lookup failed", "err", err) m.logger.Warn("subsonic: scrobble mix lookup failed", "err", err)