Skip to content

Commit

Permalink
can't math today. Fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkomarov committed Sep 12, 2024
1 parent 33275f5 commit 9ca34ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions exportify.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PlaylistTable extends React.Component {
playlists.push(response.items)
let requests = []
for (let offset = 50; offset < response.total; offset += 50) {
requests.push(utils.apiCall("https://api.spotify.com/v1/me/playlists?limit=50&offset=" + offset, this.props.access_token, 2*offset))
requests.push(utils.apiCall("https://api.spotify.com/v1/me/playlists?limit=50&offset=" + offset, this.props.access_token, ((offset-50)/50)*100))
}
await Promise.all(requests).then(responses => responses.map(response => playlists.push(response.items)))

Expand Down Expand Up @@ -186,7 +186,7 @@ let PlaylistExporter = {
let requests = []
for (let offset = 0; offset < playlist.tracks.total; offset += increment) {
requests.push(utils.apiCall(playlist.tracks.href + '?offset=' + offset + '&limit=' + increment, access_token,
~~(offset/increment)*100)) // ~~(a/b) accomplishes integer division. I'm spacing requests by 100ms regardless of increment.
(offset/increment)*100)) // I'm spacing requests by 100ms regardless of increment.
}
// "returns a single Promise that resolves when all of the promises passed as an iterable have resolved"
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
Expand Down

1 comment on commit 9ca34ce

@pavelkomarov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2*offset would mean the first call is delayed by 100ms, then the next by 200ms, the next by 300ms. I really want to delay by 0ms, 100ms, 200ms, which can be accomplished by subtracting 100ms from the above, but (maybe a bit clearer, maybe not) can also be accomplished by taking offset-50 (which starts at 0), dividing by 50 (so the result increments by 1 each loop), and multiplying that by 100ms.

Also, it turns out I didn't need integer division.

Please # to comment.