Cleaning code; Updating spotify POST requests and LastFM signed to use fetch
This commit is contained in:
@ -84,35 +84,26 @@ const sendSignedRequest = (dispatch, getState, params) => new Promise((resolve,
|
||||
dispatch(uiActions.startLoading(loader_key, `lastfm_${method}`));
|
||||
|
||||
params += `&sk=${getState().lastfm.authorization.key}`;
|
||||
const url = `${getState().lastfm.authorization_url}?action=sign_request&${params}`;
|
||||
|
||||
const config = {
|
||||
method: 'GET',
|
||||
cache: false,
|
||||
timeout: 30000,
|
||||
url: `${getState().lastfm.authorization_url}?action=sign_request&${params}`,
|
||||
};
|
||||
|
||||
// Get our server proxy to sign our request
|
||||
$.ajax(config).then(
|
||||
(response) => {
|
||||
fetch(url, config)
|
||||
.then(signResponse => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
|
||||
// Now we have signed params, we can make the actual request
|
||||
sendRequest(dispatch, getState, response.params, true)
|
||||
sendRequest(dispatch, getState, signResponse.params, true)
|
||||
.then(
|
||||
(response) => {
|
||||
resolve(response);
|
||||
},
|
||||
(error) => {
|
||||
reject(error);
|
||||
},
|
||||
response => resolve(response),
|
||||
error => reject(error),
|
||||
);
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
reject(error);
|
||||
},
|
||||
);
|
||||
})
|
||||
.catch(error => reject(error));
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -47,9 +47,9 @@ const request = (dispatch, getState, endpoint, method = 'GET', data = false, cac
|
||||
// only if we've got data do we add it to the request (this prevents appending of "&false" to the URL)
|
||||
if (data) {
|
||||
if (typeof (data) === 'string') {
|
||||
config.data = data;
|
||||
config.body = data;
|
||||
} else {
|
||||
config.data = JSON.stringify(data);
|
||||
config.body = JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user