Same .me format for providers; CORS for Genius

This commit is contained in:
James Barnsley
2018-08-17 16:09:36 +12:00
parent d48cdd9f45
commit b9f53d8d83
12 changed files with 211 additions and 64 deletions

View File

@ -27,16 +27,8 @@ var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) =
var config = {
method: method,
url: 'https://api.genius.com/'+endpoint+'?access_token='+getState().genius.access_token,
dataType: 'jsonp',
timeout: 30000,
crossDomain: true,
async: true,
headers: {
// We can't use headers as this seems to trigger CORS issues. Instead we have to post as URL params
// Authorization: 'Bearer '+ getState().genius.access_token,
Accept: 'application/json',
"Access-Control-Allow-Origin": "*"
}
crossDomain: true
}
// only if we've got data do we add it to the request (this prevents appending of "&false" to the URL)
@ -113,13 +105,10 @@ export function getMe(){
});
},
error => {
console.log(error);
/*
dispatch(coreActions.handleException(
'Could not load your Genius profile',
error
));
*/
}
);
}

View File

@ -0,0 +1,39 @@
var helpers = require('./../../helpers')
var coreActions = require('../core/actions')
const GeniusMiddleware = (function(){
return store => next => action => {
var state = store.getState();
switch(action.type){
case 'GENIUS_ME_LOADED':
store.dispatch({
type: 'GENIUS_USER_LOADED',
user: action.me
});
next(action);
break;
case 'GENIUS_USER_LOADED':
var user = Object.assign(
{},
action.user,
{
uri: "genius:user:"+action.user.id
}
);
store.dispatch(coreActions.userLoaded(user));
next(action);
break;
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);
}
}
})();
export default GeniusMiddleware

View File

@ -164,10 +164,9 @@ export function getMe(){
response => {
if (response.user){
dispatch({
type: 'LASTFM_USER_LOADED',
user: response.user
type: 'LASTFM_ME_LOADED',
me: response.user
});
dispatch({ type: 'LASTFM_CONNECTED' })
}
}
)

View File

@ -14,6 +14,14 @@ const LastfmMiddleware = (function(){
switch(action.type){
case 'LASTFM_ME_LOADED':
store.dispatch({
type: 'LASTFM_USER_LOADED',
user: action.me
});
next(action);
break;
case 'LASTFM_USER_LOADED':
var user = Object.assign(
{},
@ -22,10 +30,7 @@ const LastfmMiddleware = (function(){
uri: "lastfm:user:"+action.user.name
}
);
store.dispatch({
type: "USERS_LOADED",
users: [user]
});
store.dispatch(coreActions.userLoaded(user));
next(action);
break;

View File

@ -12,6 +12,11 @@ export default function reducer(lastfm = {}, action){
case 'LASTFM_SET':
return Object.assign({}, lastfm, action.data)
case 'LASTFM_ME_LOADED':
return Object.assign({}, lastfm, {
me: action.me
})
case 'LASTFM_AUTHORIZATION_GRANTED':
return Object.assign({}, lastfm, {
authorizing: false,

View File

@ -117,6 +117,15 @@ const localstorageMiddleware = (function(){
);
break;
case 'LASTFM_ME_LOADED':
helpers.setStorage(
'lastfm',
{
me: action.data.session.user
}
);
break;
case 'LASTFM_AUTHORIZATION_GRANTED':
helpers.setStorage(
'lastfm',
@ -135,6 +144,15 @@ const localstorageMiddleware = (function(){
);
break;
case 'GENIUS_ME_LOADED':
helpers.setStorage(
'genius',
{
me: action.me
}
);
break;
case 'GENIUS_AUTHORIZATION_GRANTED':
helpers.setStorage(
'genius',