Upgrading subsequent Genius API calls to fetch()
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -100,7 +100,7 @@
|
||||
|
||||
// Release details
|
||||
// These are automatically injected to built HTML
|
||||
var build = "1581967948";
|
||||
var build = "1581968126";
|
||||
var version = "3.44.3";
|
||||
|
||||
// Construct the script tag
|
||||
|
||||
@ -30,6 +30,10 @@ const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false)
|
||||
}
|
||||
}
|
||||
|
||||
if (data) {
|
||||
url += `&${data}`;
|
||||
}
|
||||
|
||||
// create our ajax request config
|
||||
const config = {
|
||||
method,
|
||||
@ -148,9 +152,9 @@ export function getTrackLyrics(uri, path) {
|
||||
lyrics_path: null,
|
||||
}));
|
||||
|
||||
const url = `//${getState().mopidy.host}:${getState().mopidy.port}/iris/http/get_lyrics?path=${path}&connection_id=${getState().pusher.connection_id}`;
|
||||
const config = {
|
||||
method: 'GET',
|
||||
url: `//${getState().mopidy.host}:${getState().mopidy.port}/iris/http/get_lyrics?path=${path}&connection_id=${getState().pusher.connection_id}`,
|
||||
timeout: 10000,
|
||||
};
|
||||
|
||||
@ -158,42 +162,49 @@ export function getTrackLyrics(uri, path) {
|
||||
const loader_key = helpers.generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, 'genius_get_lyrics'));
|
||||
|
||||
$.ajax(config)
|
||||
.then(
|
||||
(response, status, xhr) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
if (response && response.result) {
|
||||
const html = $(response.result);
|
||||
let lyrics = html.find('.lyrics');
|
||||
if (lyrics.length > 0) {
|
||||
lyrics = lyrics.first();
|
||||
lyrics.find('a').replaceWith((k, v) => v);
|
||||
function status(response) {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
|
||||
let lyrics_html = lyrics.html();
|
||||
lyrics_html = lyrics_html.replace(/(\[)/g, '<span class="mid_grey-text">[');
|
||||
lyrics_html = lyrics_html.replace(/(\])/g, ']</span>');
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return Promise.resolve(response);
|
||||
}
|
||||
return Promise.reject(new Error(response.statusText));
|
||||
}
|
||||
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri,
|
||||
lyrics: lyrics_html,
|
||||
lyrics_path: path,
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not get track lyrics',
|
||||
response.error,
|
||||
));
|
||||
fetch(url, config)
|
||||
.then(status)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.result) {
|
||||
const html = $(data.result);
|
||||
let lyrics = html.find('.lyrics');
|
||||
if (lyrics.length > 0) {
|
||||
lyrics = lyrics.first();
|
||||
lyrics.find('a').replaceWith((k, v) => v);
|
||||
|
||||
let lyrics_html = lyrics.html();
|
||||
lyrics_html = lyrics_html.replace(/(\[)/g, '<span class="mid_grey-text">[');
|
||||
lyrics_html = lyrics_html.replace(/(\])/g, ']</span>');
|
||||
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri,
|
||||
lyrics: lyrics_html,
|
||||
lyrics_path: path,
|
||||
}));
|
||||
}
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
} else {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not get track lyrics',
|
||||
error,
|
||||
data.error,
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not get track lyrics',
|
||||
error,
|
||||
));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user