Auto eslint fix
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
|
||||
var coreActions = require('../core/actions');
|
||||
var uiActions = require('../ui/actions');
|
||||
var helpers = require('../../helpers');
|
||||
const coreActions = require('../core/actions');
|
||||
const uiActions = require('../ui/actions');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
export function set(data){
|
||||
return {
|
||||
type: 'GENIUS_SET',
|
||||
data: data
|
||||
}
|
||||
export function set(data) {
|
||||
return {
|
||||
type: 'GENIUS_SET',
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -19,115 +19,112 @@ export function set(data){
|
||||
* @param method string
|
||||
* @param data mixed = request payload
|
||||
* @return Promise
|
||||
**/
|
||||
var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
* */
|
||||
const sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) => new Promise((resolve, reject) => {
|
||||
if (endpoint.startsWith('https://') || endpoint.startsWith('http://')) {
|
||||
var url = endpoint;
|
||||
} else {
|
||||
var url = `https://api.genius.com/${endpoint}`;
|
||||
if (getState().genius.access_token) {
|
||||
url += `?access_token=${getState().genius.access_token}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (endpoint.startsWith('https://') || endpoint.startsWith('http://')){
|
||||
var url = endpoint;
|
||||
} else {
|
||||
var url = 'https://api.genius.com/'+endpoint;
|
||||
if (getState().genius.access_token){
|
||||
url += '?access_token='+getState().genius.access_token;
|
||||
}
|
||||
}
|
||||
// create our ajax request config
|
||||
const config = {
|
||||
method,
|
||||
url,
|
||||
timeout: 30000,
|
||||
crossDomain: true,
|
||||
};
|
||||
|
||||
// create our ajax request config
|
||||
var config = {
|
||||
method: method,
|
||||
url: url,
|
||||
timeout: 30000,
|
||||
crossDomain: true
|
||||
}
|
||||
// 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;
|
||||
} else {
|
||||
config.data = JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
} else {
|
||||
config.data = JSON.stringify(data)
|
||||
}
|
||||
}
|
||||
// add reference to loader queue
|
||||
const loader_key = helpers.generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, `genius_${endpoint}`));
|
||||
|
||||
// add reference to loader queue
|
||||
var loader_key = helpers.generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, 'genius_'+endpoint));
|
||||
$.ajax(config).then(
|
||||
(response) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
|
||||
$.ajax(config).then(
|
||||
response => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
|
||||
if (response.meta && response.meta.status >= 200 && response.meta.status < 300 && response.response){
|
||||
resolve(response.response);
|
||||
} else {
|
||||
reject({
|
||||
config: config,
|
||||
xhr: xhr,
|
||||
status: status,
|
||||
error: error
|
||||
});
|
||||
}
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
reject({
|
||||
config: config,
|
||||
xhr: xhr,
|
||||
status: status,
|
||||
error: error
|
||||
});
|
||||
}
|
||||
)
|
||||
});
|
||||
}
|
||||
if (response.meta && response.meta.status >= 200 && response.meta.status < 300 && response.response) {
|
||||
resolve(response.response);
|
||||
} else {
|
||||
reject({
|
||||
config,
|
||||
xhr,
|
||||
status,
|
||||
error,
|
||||
});
|
||||
}
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
reject({
|
||||
config,
|
||||
xhr,
|
||||
status,
|
||||
error,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Handle authorization process
|
||||
**/
|
||||
* */
|
||||
|
||||
export function authorizationGranted(data){
|
||||
return {
|
||||
type: 'GENIUS_AUTHORIZATION_GRANTED',
|
||||
data: data
|
||||
}
|
||||
export function authorizationGranted(data) {
|
||||
return {
|
||||
type: 'GENIUS_AUTHORIZATION_GRANTED',
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
export function revokeAuthorization(){
|
||||
return {
|
||||
type: 'GENIUS_AUTHORIZATION_REVOKED'
|
||||
}
|
||||
export function revokeAuthorization() {
|
||||
return {
|
||||
type: 'GENIUS_AUTHORIZATION_REVOKED',
|
||||
};
|
||||
}
|
||||
|
||||
export function importAuthorization(authorization){
|
||||
return {
|
||||
type: 'GENIUS_IMPORT_AUTHORIZATION',
|
||||
authorization: authorization
|
||||
}
|
||||
export function importAuthorization(authorization) {
|
||||
return {
|
||||
type: 'GENIUS_IMPORT_AUTHORIZATION',
|
||||
authorization,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current user
|
||||
**/
|
||||
export function getMe(){
|
||||
return (dispatch, getState) => {
|
||||
sendRequest(dispatch, getState, 'account')
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'GENIUS_ME_LOADED',
|
||||
me: response.user
|
||||
});
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not load your Genius profile',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
}
|
||||
* */
|
||||
export function getMe() {
|
||||
return (dispatch, getState) => {
|
||||
sendRequest(dispatch, getState, 'account')
|
||||
.then(
|
||||
(response) => {
|
||||
dispatch({
|
||||
type: 'GENIUS_ME_LOADED',
|
||||
me: response.user,
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not load your Genius profile',
|
||||
error,
|
||||
));
|
||||
},
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,108 +133,104 @@ export function getMe(){
|
||||
*
|
||||
* @param uri = track uri
|
||||
* @param path = String, the relative API path for the HTML lyrics
|
||||
**/
|
||||
export function getTrackLyrics(uri, path){
|
||||
return (dispatch, getState) => {
|
||||
* */
|
||||
export function getTrackLyrics(uri, path) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri,
|
||||
lyrics: null,
|
||||
lyrics_path: null,
|
||||
}));
|
||||
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri: uri,
|
||||
lyrics: null,
|
||||
lyrics_path: null
|
||||
}));
|
||||
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,
|
||||
};
|
||||
|
||||
var config = {
|
||||
method: 'GET',
|
||||
url: '//'+getState().mopidy.host+':'+getState().mopidy.port+'/iris/http/get_lyrics?path='+path+'&connection_id='+getState().pusher.connection_id,
|
||||
timeout: 10000
|
||||
}
|
||||
// add reference to loader queue
|
||||
const loader_key = helpers.generateGuid();
|
||||
dispatch(uiActions.startLoading(loader_key, 'genius_get_lyrics'));
|
||||
|
||||
// add reference to loader queue
|
||||
var 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){
|
||||
var html = $(response.result);
|
||||
var lyrics = html.find('.lyrics');
|
||||
if (lyrics.length > 0){
|
||||
$.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(function(){
|
||||
lyrics.find('a').replaceWith(function () {
|
||||
return this.innerHTML;
|
||||
});
|
||||
|
||||
var lyrics_html = lyrics.html();
|
||||
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: uri,
|
||||
lyrics: lyrics_html,
|
||||
lyrics_path: path
|
||||
}));
|
||||
uri,
|
||||
lyrics: lyrics_html,
|
||||
lyrics_path: path,
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not get track lyrics',
|
||||
response.error
|
||||
response.error,
|
||||
));
|
||||
}
|
||||
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not get track lyrics',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
(xhr, status, error) => {
|
||||
dispatch(uiActions.stopLoading(loader_key));
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not get track lyrics',
|
||||
error,
|
||||
));
|
||||
},
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function findTrackLyrics(track){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
var query = '';
|
||||
query += track.artists[0].name+' ';
|
||||
query += track.name;
|
||||
query = query.toLowerCase();
|
||||
query = query.replace(/\([^)]*\) */g, ''); // anything in circle-braces
|
||||
query = query.replace(/\([^[]*\] */g, ''); // anything in square-braces
|
||||
export function findTrackLyrics(track) {
|
||||
return (dispatch, getState) => {
|
||||
let query = '';
|
||||
query += `${track.artists[0].name} `;
|
||||
query += track.name;
|
||||
query = query.toLowerCase();
|
||||
query = query.replace(/\([^)]*\) */g, ''); // anything in circle-braces
|
||||
query = query.replace(/\([^[]*\] */g, ''); // anything in square-braces
|
||||
|
||||
sendRequest(dispatch, getState, 'search', 'GET', 'q='+encodeURIComponent(query))
|
||||
.then(
|
||||
response => {
|
||||
if (response.hits && response.hits.length > 0){
|
||||
var lyrics_results = [];
|
||||
for (var i = 0; i < response.hits.length; i++){
|
||||
lyrics_results.push({
|
||||
title: response.hits[i].result.full_title,
|
||||
url: response.hits[i].result.url,
|
||||
path: response.hits[i].result.path
|
||||
});
|
||||
}
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri: track.uri,
|
||||
lyrics_results: lyrics_results
|
||||
}));
|
||||
sendRequest(dispatch, getState, 'search', 'GET', `q=${encodeURIComponent(query)}`)
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.hits && response.hits.length > 0) {
|
||||
const lyrics_results = [];
|
||||
for (let i = 0; i < response.hits.length; i++) {
|
||||
lyrics_results.push({
|
||||
title: response.hits[i].result.full_title,
|
||||
url: response.hits[i].result.url,
|
||||
path: response.hits[i].result.path,
|
||||
});
|
||||
}
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri: track.uri,
|
||||
lyrics_results,
|
||||
}));
|
||||
|
||||
// Immediately go and get the first result's lyrics
|
||||
var lyrics_result = lyrics_results[0];
|
||||
dispatch(getTrackLyrics(track.uri, lyrics_result.path));
|
||||
}
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not search for track lyrics',
|
||||
error
|
||||
));
|
||||
}
|
||||
);
|
||||
}
|
||||
// Immediately go and get the first result's lyrics
|
||||
const lyrics_result = lyrics_results[0];
|
||||
dispatch(getTrackLyrics(track.uri, lyrics_result.path));
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not search for track lyrics',
|
||||
error,
|
||||
));
|
||||
},
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user