LastFM authorization format; Sharing config working

This commit is contained in:
James Barnsley
2018-10-01 21:51:46 +13:00
parent ba0f780c28
commit 85c5786d9e
18 changed files with 12014 additions and 15081 deletions

View File

@ -87,10 +87,10 @@ const sendSignedRequest = (dispatch, getState, params) => {
return new Promise((resolve, reject) => {
// Not authorized
if (!getState().lastfm.session){
if (!getState().lastfm.authorization){
reject({
params: params,
error: "No active LastFM session"
error: "No active LastFM authorization (session)"
});
}
@ -100,7 +100,7 @@ const sendSignedRequest = (dispatch, getState, params) => {
dispatch(uiActions.startLoading(loader_key, 'lastfm_'+method));
params += "&sk="+getState().lastfm.session.key;
params += "&sk="+getState().lastfm.authorization.key;
var config = {
method: 'GET',
@ -167,7 +167,7 @@ export function importAuthorization(authorization){
export function getMe(){
return (dispatch, getState) => {
var params = 'method=user.getInfo&user='+getState().lastfm.session.name
var params = 'method=user.getInfo&user='+getState().lastfm.authorization.name
sendRequest(dispatch, getState, params)
.then(
response => {
@ -206,8 +206,8 @@ export function getTrack(uri){
var track_name = track.name;
var artist_name = encodeURIComponent(track.artists[0].name);
var params = 'method=track.getInfo&track='+track_name+'&artist='+artist_name;
if (getState().lastfm.session){
params += '&username='+getState().lastfm.session.name;
if (getState().lastfm.authorization){
params += '&username='+getState().lastfm.authorization.name;
}
sendRequest(dispatch, getState, params)
.then(

View File

@ -20,20 +20,20 @@ export default function reducer(lastfm = {}, action){
case 'LASTFM_AUTHORIZATION_GRANTED':
return Object.assign({}, lastfm, {
authorizing: false,
session: action.data.session
authorization: action.data.session
})
case 'LASTFM_AUTHORIZATION_REVOKED':
return Object.assign({}, lastfm, {
authorizing: false,
session: false,
authorization: false,
me: null
});
case 'LASTFM_IMPORT_AUTHORIZATION':
return Object.assign({}, lastfm, {
authorizing: false,
session: action.authorization,
authorization: action.authorization,
me: null
});

View File

@ -67,7 +67,6 @@ const localstorageMiddleware = (function(){
);
break;
case 'SPOTIFY_IMPORT_AUTHORIZATION':
case 'SPOTIFY_AUTHORIZATION_GRANTED':
if (action.authorization !== undefined){
var authorization = action.authorization;
@ -85,14 +84,28 @@ const localstorageMiddleware = (function(){
);
break;
case 'SPOTIFY_IMPORT_AUTHORIZATION':
helpers.setStorage(
'spotify',
{
authorization: action.authorization,
access_token: action.authorization.access_token,
refresh_token: action.authorization.refresh_token,
token_expiry: action.authorization.token_expiry,
me: null
}
);
break;
case 'SPOTIFY_AUTHORIZATION_REVOKED':
helpers.setStorage(
'spotify',
{
authorization: false,
access_token: false,
refresh_token: false,
token_expiry: false
authorization: null,
access_token: null,
refresh_token: null,
token_expiry: null,
me: null
}
);
break;
@ -130,7 +143,7 @@ const localstorageMiddleware = (function(){
helpers.setStorage(
'lastfm',
{
session: action.data.session
authorization: action.data.session
}
);
break;
@ -139,7 +152,18 @@ const localstorageMiddleware = (function(){
helpers.setStorage(
'lastfm',
{
session: null
authorization: null,
me: null
}
);
break;
case 'LASTFM_IMPORT_AUTHORIZATION':
helpers.setStorage(
'lastfm',
{
authorization: action.authorization,
me: null
}
);
break;
@ -176,6 +200,18 @@ const localstorageMiddleware = (function(){
);
break;
case 'GENIUS_IMPORT_AUTHORIZATION':
helpers.setStorage(
'genius',
{
authorization: action.authorization,
authorization_code: action.authorization.authorization_code,
access_token: action.authorization.access_token,
me: null
}
);
break;
case 'CORE_SET':
helpers.setStorage(
'core',

View File

@ -54,12 +54,11 @@ const SpotifyMiddleware = (function(){
// Flush out the previous user's library
store.dispatch(spotifyActions.flushLibrary());
// Pass to reducer
// Wait a few moments before we fetch, allowing the import to complete first
// TODO: Use callbacks for better code accuracy
setTimeout(() => {store.dispatch(spotifyActions.getMe())}, 100);
next(action);
// Then get the new user
store.dispatch(spotifyActions.getMe());
break;
case 'SPOTIFY_RECOMMENDATIONS_LOADED':

View File

@ -43,7 +43,7 @@ export default function reducer(spotify = {}, action){
access_token: action.authorization.access_token,
refresh_token: action.authorization.refresh_token,
token_expiry: action.authorization.token_expiry,
me: false
me: action.me
});
case 'SPOTIFY_TOKEN_REFRESHING':