Removing authorized, just use authorization

This commit is contained in:
James Barnsley
2017-08-04 22:01:50 +12:00
parent 4213a513da
commit c2b8cfb346
10 changed files with 113 additions and 86 deletions

View File

@ -1034,8 +1034,14 @@ const MopidyMiddleware = (function(){
// Fire off our universal track index loader
store.dispatch({ type: 'TRACK_LOADED', key: action.data.track.uri, track: action.data.track })
// Get me some images
store.dispatch(mopidyActions.getImages('tracks',[action.data.track.uri]))
// We've got Spotify running, and it's a spotify track - go straight to the source!
if (helpers.uriSource(action.data.track.uri) == 'spotify' && store.getState().spotify.access != 'none'){
store.dispatch(spotifyActions.getTrack(action.data.track.uri))
// Some other source, rely on Mopidy backends to do their work
} else {
store.dispatch(mopidyActions.getImages('tracks',[action.data.track.uri]))
}
}
next(action)

View File

@ -126,7 +126,7 @@ function refreshToken( dispatch, getState ){
response.source = 'spotify'
dispatch({
type: 'SPOTIFY_TOKEN_REFRESHED',
provider: 'spotify-http-api',
access_token_provider: 'http_api',
data: response
})
resolve(response)
@ -154,7 +154,7 @@ function refreshToken( dispatch, getState ){
token.source = 'mopidy';
dispatch({
type: 'SPOTIFY_TOKEN_REFRESHED',
provider: 'mopidy-spotify',
access_token_provider: 'backend',
data: token
});
resolve(token);
@ -257,9 +257,17 @@ export function getTrack( uri ){
sendRequest( dispatch, getState, 'tracks/'+ helpers.getFromUri('trackid', uri) )
.then( response => {
let track = Object.assign(
{},
response,
{
images: response.album.images
}
)
dispatch({
type: 'SPOTIFY_TRACK_LOADED',
data: response
type: 'TRACK_LOADED',
key: uri,
track: track
});
}
);

View File

@ -15,13 +15,21 @@ export default function reducer(spotify = {}, action){
return Object.assign({}, spotify, { connected: false, connecting: false })
case 'SPOTIFY_SET_CONFIG':
return Object.assign({}, spotify, action.config)
var spotify = Object.assign({},spotify,action.config)
let access = 'none'
if (spotify.authentication_provider == 'http_api' && spotify.authorized){
access = 'full'
} else if (spotify.authentication_provider == 'backend' && spotify.backend_username){
access = 'limited'
}
spotify.access = access
return spotify
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
@ -29,8 +37,8 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_AUTHORIZATION_GRANTED':
return Object.assign({}, spotify, {
access: (spotify.authentication_provider == 'http_api' ? 'full' : 'limited'),
authorizing: false,
authorized: true,
authorization: action.data,
access_token: action.data.access_token,
refresh_token: action.data.refresh_token,
@ -39,9 +47,9 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_AUTHORIZATION_REVOKED':
return Object.assign({}, spotify, {
access: (spotify.authentication_provider == 'http_api' ? 'none' : 'limited'),
authorizing: false,
authorization: false,
authorized: false,
access_token: false,
refresh_token: false,
token_expiry: 0,
@ -50,8 +58,9 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_IMPORT_AUTHORIZATION':
return Object.assign({}, spotify, {
authentication_provider: 'http_api',
access: 'full',
authorizing: false,
authorized: true,
authorization: action.authorization,
access_token: action.authorization.access_token,
refresh_token: action.authorization.refresh_token,
@ -68,7 +77,7 @@ export default function reducer(spotify = {}, action){
refreshing_token: false,
access_token: action.data.access_token,
token_expiry: action.data.token_expiry,
provider: action.provider
access_token_provider: action.access_token_provider
})
case 'SPOTIFY_DISCONNECTED':
@ -76,26 +85,6 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_ME_LOADED':
return Object.assign({}, spotify, { me: action.data })
/*
case 'SPOTIFY_ARTISTS_LOADED':
if( !action.data ) return Object.assign({}, spotify)
return Object.assign({}, spotify, {
artists: action.data.artists.items,
artists_more: action.data.artists.next
})
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
if( !action.data ) return Object.assign({}, spotify)
return Object.assign({}, spotify, {
library_artists: action.data.artists.items,
library_artists_more: action.data.artists.next
})
case 'SPOTIFY_LIBRARY_ARTISTS_LOADED_MORE':
return Object.assign({}, spotify, {
library_artists: [ ...spotify.library_artists, ...action.data.artists.items ],
library_artists_more: action.data.artists.next
})*/
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
if( !action.data ) return Object.assign({}, spotify)