Version manager for pusher; Local spotify tokens
This commit is contained in:
@ -101,26 +101,56 @@ function getToken( dispatch, getState ){
|
||||
|
||||
function refreshToken( dispatch, getState ){
|
||||
return new Promise( (resolve, reject) => {
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: '//jamesbarnsley.co.nz/spotmop.php?action=refresh&refresh_token='+getState().spotify.refresh_token,
|
||||
dataType: "json",
|
||||
timeout: 10000
|
||||
})
|
||||
.then(
|
||||
response => {
|
||||
response.token_expiry = new Date().getTime() + ( response.expires_in * 1000 );
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
data: response
|
||||
});
|
||||
resolve(response);
|
||||
},
|
||||
error => {
|
||||
console.error('Could not refresh token', error)
|
||||
reject(error)
|
||||
}
|
||||
);
|
||||
|
||||
if( getState().spotify.authorized ){
|
||||
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: '//jamesbarnsley.co.nz/spotmop.php?action=refresh&refresh_token='+getState().spotify.refresh_token,
|
||||
dataType: "json",
|
||||
timeout: 10000
|
||||
})
|
||||
.then(
|
||||
response => {
|
||||
response.token_expiry = new Date().getTime() + ( response.expires_in * 1000 );
|
||||
response.source = 'spotify';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
data: response
|
||||
});
|
||||
resolve(response);
|
||||
},
|
||||
error => {
|
||||
console.error('Could not refresh token', error)
|
||||
reject(error)
|
||||
}
|
||||
);
|
||||
|
||||
}else{
|
||||
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: '//'+getState().mopidy.host+':'+getState().mopidy.port+'/spotmop/http?action=refresh_spotify_token',
|
||||
dataType: "json",
|
||||
timeout: 10000
|
||||
})
|
||||
.then(
|
||||
response => {
|
||||
response.token_expiry = new Date().getTime() + ( response.expires_in * 1000 );
|
||||
response.source = 'mopidy';
|
||||
dispatch({
|
||||
type: 'SPOTIFY_TOKEN_REFRESHED',
|
||||
data: response
|
||||
});
|
||||
resolve(response);
|
||||
},
|
||||
error => {
|
||||
console.error('Could not refresh token', error)
|
||||
reject(error)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,16 @@ export default function reducer(spotify = {}, action){
|
||||
token_expiry: action.data.token_expiry
|
||||
});
|
||||
|
||||
case 'PUSHER_SPOTIFY_TOKEN':
|
||||
if( spotify.authorized ) return spotify;
|
||||
return Object.assign({}, spotify, {
|
||||
authorizing: false,
|
||||
authorized: false,
|
||||
authorization: false,
|
||||
access_token: action.data.access_token,
|
||||
token_expiry: action.data.token_expiry
|
||||
});
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
return Object.assign({}, spotify, {
|
||||
authorizing: false,
|
||||
|
||||
Reference in New Issue
Block a user