mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-10 12:11:35 +02:00
Retry Spotify token refresh
This commit is contained in:
parent
28bcd4b45e
commit
e489b10565
4 changed files with 23 additions and 5 deletions
|
@ -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});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue