Fix per-user Last.fm integration - #80
Conversation
e1b303b to
6d1699e
Compare
6d1699e to
858a75a
Compare
| /** Increments whenever a new track playback starts, including repeats */ | ||
| playbackInstance: number; |
There was a problem hiding this comment.
"instance" sounds like it's an instance of a playback while this is a counter. Right?
My suggestion:
| /** Increments whenever a new track playback starts, including repeats */ | |
| playbackInstance: number; | |
| /** Increments whenever a new track playback starts, including repeats. Used by Last.fm to keep track of new plays. */ | |
| playbackCount: number; |
Also, do we have comprehensive tests to make sure this is incremented correctly in every situation?
There was a problem hiding this comment.
Random irrelevant interesting question, no need to act: Can this overflow over time…? If someone keeps player open for a LONG TIME?
| } | ||
|
|
||
| return { | ||
| playbackInstance: isResume ? state.playbackInstance : state.playbackInstance + 1, |
There was a problem hiding this comment.
Let's inline the isResume, easier to read the flow of the code:
| playbackInstance: isResume ? state.playbackInstance : state.playbackInstance + 1, | |
| // Increase playback count when we are playing new jams. | |
| playbackCount: state.state === 'paused' ? state.playbackCount : state.playbackCount + 1, |
| Username string `json:"username"` | ||
| Password string `json:"password"` | ||
| LastFMUsername string `json:"lastfm_username,omitempty"` | ||
| LastFMSession string `json:"lastfm_session,omitempty"` | ||
| LastFMToken string `json:"lastfm_token,omitempty"` |
There was a problem hiding this comment.
| Username string `json:"username"` | |
| Password string `json:"password"` | |
| LastFMUsername string `json:"lastfm_username,omitempty"` | |
| LastFMSession string `json:"lastfm_session,omitempty"` | |
| LastFMToken string `json:"lastfm_token,omitempty"` | |
| Username string `json:"username"` | |
| Password string `json:"password"` | |
| LastFMUsername string `json:"lastfm_username,omitempty"` | |
| LastFMSession string `json:"lastfm_session,omitempty"` | |
| LastFMToken string `json:"lastfm_token,omitempty"` |
| }), | ||
| }).catch((error: unknown) => { | ||
| console.error(`Could not scrobble ${song.artist} — ${song.title}`, error); | ||
| if (error instanceof ApiError && error.status === 409) void mutate('/api/lastfm'); |
There was a problem hiding this comment.
What are we doing here and why? Add comment, and also add { }
|
|
||
| export const LastFMScrobbler = () => { | ||
| const { data: lastFM } = useLastFM(); | ||
| const scrobbledInstances = useRef(new Map<string, number>()); |
There was a problem hiding this comment.
Let's simplify this, we won't need multi-user in-memory support – we can easily reload the page on logout (and we should, for memory-security, but let's fix that separately).
| const scrobbledInstances = useRef(new Map<string, number>()); | |
| const scrobbleCounter = useRef<number>(); |
| const [changingPassword, setChangingPassword] = useState(false); | ||
| const { data: lastFM } = useLastFM(); | ||
| const [busy, setBusy] = useState(false); | ||
| const [error, setError] = useState(''); |
There was a problem hiding this comment.
Rename:
| const [error, setError] = useState(''); | |
| const [lastfmError, setLastfmError] = useState(''); |
Co-authored-by: AJ Kovalainen <ajk@ajk.fi>
| http.Error(w, "Invalid password", http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
There was a problem hiding this comment.
Undo this removal of a newline.
|
Squashed to master manually, closing. |
Summary
Verification
npm run typechecknpm run builddocker build -f Dockerfile.hub -t beatstream-lastfm-check .docker run --rm beatstream-lastfm-test go test ./...Repository-wide frontend lint still reports pre-existing violations outside this change.