mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
Retry Spotify token refresh
This commit is contained in:
parent
28bcd4b45e
commit
e489b10565
|
@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Retry refreshing Spotify access token if a request fails (should fix https://github.com/codetheweb/muse/issues/719)
|
||||
|
||||
## [2.1.0] - 2022-06-25
|
||||
- `/loop` command that plays the current song on loop
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
"p-event": "^5.0.1",
|
||||
"p-limit": "^4.0.0",
|
||||
"p-queue": "^7.2.0",
|
||||
"p-retry": "4.6.2",
|
||||
"parse-duration": "1.0.2",
|
||||
"read-pkg": "7.1.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {inject, injectable} from 'inversify';
|
||||
import SpotifyWebApi from 'spotify-web-api-node';
|
||||
import Youtube from 'youtube.ts';
|
||||
import pRetry from 'p-retry';
|
||||
import {TYPES} from '../types.js';
|
||||
import Config from './config.js';
|
||||
|
||||
|
@ -30,9 +31,10 @@ export default class ThirdParty {
|
|||
}
|
||||
|
||||
private async refreshSpotifyToken() {
|
||||
const auth = await this.spotify.clientCredentialsGrant();
|
||||
this.spotify.setAccessToken(auth.body.access_token);
|
||||
|
||||
this.spotifyTokenTimerId = setTimeout(this.refreshSpotifyToken.bind(this), (auth.body.expires_in / 2) * 1000);
|
||||
await pRetry(async () => {
|
||||
const auth = await this.spotify.clientCredentialsGrant();
|
||||
this.spotify.setAccessToken(auth.body.access_token);
|
||||
this.spotifyTokenTimerId = setTimeout(this.refreshSpotifyToken.bind(this), (auth.body.expires_in / 2) * 1000);
|
||||
}, {retries: 5});
|
||||
}
|
||||
}
|
||||
|
|
15
yarn.lock
15
yarn.lock
|
@ -441,6 +441,11 @@
|
|||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/retry@0.12.0":
|
||||
version "0.12.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
|
||||
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==
|
||||
|
||||
"@types/spotify-api@*":
|
||||
version "0.0.15"
|
||||
resolved "https://registry.yarnpkg.com/@types/spotify-api/-/spotify-api-0.0.15.tgz#c5f257159194f085cc05b70c0012ac80c6103199"
|
||||
|
@ -3233,6 +3238,14 @@ p-queue@^7.2.0:
|
|||
eventemitter3 "^4.0.7"
|
||||
p-timeout "^5.0.2"
|
||||
|
||||
p-retry@4.6.2:
|
||||
version "4.6.2"
|
||||
resolved "https://registry.yarnpkg.com/p-retry/-/p-retry-4.6.2.tgz#9baae7184057edd4e17231cee04264106e092a16"
|
||||
integrity sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==
|
||||
dependencies:
|
||||
"@types/retry" "0.12.0"
|
||||
retry "^0.13.1"
|
||||
|
||||
p-timeout@^5.0.2:
|
||||
version "5.0.2"
|
||||
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-5.0.2.tgz#d12964c4b2f988e15f72b455c2c428d82a0ec0a0"
|
||||
|
@ -3666,7 +3679,7 @@ restore-cursor@^4.0.0:
|
|||
onetime "^5.1.0"
|
||||
signal-exit "^3.0.2"
|
||||
|
||||
retry@0.13.1:
|
||||
retry@0.13.1, retry@^0.13.1:
|
||||
version "0.13.1"
|
||||
resolved "https://registry.yarnpkg.com/retry/-/retry-0.13.1.tgz#185b1587acf67919d63b357349e03537b2484658"
|
||||
integrity sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==
|
||||
|
|
Loading…
Reference in a new issue