Handling non-authorized Genius

This commit is contained in:
James Barnsley
2018-08-21 21:08:11 +12:00
parent e97bc4f401
commit b02e4ef1ce
9 changed files with 13906 additions and 10583 deletions

View File

@ -991,19 +991,19 @@ class IrisCore(object):
}
try:
client_id = request.get_argument('client_id')
connection_id = request.get_argument('connection_id')
if client_id not in self.connections:
if connection_id not in self.connections:
error = {
'message': 'Unauthorized request',
'description': client_id+' not connected'
'description': 'Connection '+connection_id+' not connected'
}
except Exception, e:
logger.error(e)
error = {
'message': "Unauthorized request",
'description': "client_id missing"
'description': "connection_id missing"
}
if error:

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -98,7 +98,7 @@
// Release details
// These are automatically injected to built HTML
var build = "1534641077";
var build = "1534796832";
var version = "3.23.2";
// Construct the script tag

View File

@ -131,42 +131,56 @@ export function getTrackLyrics(uri, path){
return (dispatch, getState) => {
dispatch(coreActions.trackLoaded({
uri: uri,
lyrics: null,
lyrics_path: null
}));
uri: uri,
lyrics: null,
lyrics_path: null
}));
var config = {
method: 'GET',
url: '//'+getState().mopidy.host+':'+getState().mopidy.port+'/iris/http/get_lyrics?path='+path+'&client_id='+store.getState.pusher.client_id,
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
var loader_key = helpers.generateGuid();
dispatch(uiActions.startLoading(loader_key, 'genius_get_lyrics'));
$.ajax(config)
.then(
(response, status, xhr) => {
var html = $(response);
var lyrics = html.find('.lyrics');
if (lyrics.length > 0){
dispatch(uiActions.stopLoading(loader_key));
lyrics = lyrics.first();
lyrics.find('a').replaceWith(function(){
return this.innerHTML;
});
if (response && response.result){
var html = $(response.result);
var lyrics = html.find('.lyrics');
if (lyrics.length > 0){
var lyrics_html = lyrics.html();
lyrics_html = lyrics_html.replace(/(\[)/g, '<span class="grey-text">[');
lyrics_html = lyrics_html.replace(/(\])/g, ']</span>');
lyrics = lyrics.first();
lyrics.find('a').replaceWith(function(){
return this.innerHTML;
});
dispatch(coreActions.trackLoaded({
uri: uri,
lyrics: lyrics_html,
lyrics_path: path
}));
var lyrics_html = lyrics.html();
lyrics_html = lyrics_html.replace(/(\[)/g, '<span class="grey-text">[');
lyrics_html = lyrics_html.replace(/(\])/g, ']</span>');
dispatch(coreActions.trackLoaded({
uri: uri,
lyrics: lyrics_html,
lyrics_path: path
}));
}
} else {
dispatch(coreActions.handleException(
'Could not get track lyrics',
response.error
));
}
},
(xhr, status, error) => {
dispatch(uiActions.stopLoading(loader_key));
dispatch(coreActions.handleException(
'Could not get track lyrics',
error

View File

@ -3,6 +3,14 @@ var coreActions = require('../core/actions');
var uiActions = require('../ui/actions');
var helpers = require('../../helpers');
export function set(data){
return {
type: 'LASTFM_SET',
data: data
}
}
/**
* Send an ajax request to the LastFM API
*
@ -126,14 +134,6 @@ const sendSignedRequest = (dispatch, getState, params) => {
}
export function set(data){
return {
type: 'LASTFM_SET',
data: data
}
}
/**
* Handle authorization process
**/

View File

@ -14,6 +14,11 @@ const LastfmMiddleware = (function(){
switch(action.type){
case 'LASTFM_SET':
console.log(action);
next(action);
break;
case 'LASTFM_ME_LOADED':
store.dispatch({
type: 'LASTFM_USER_LOADED',

View File

@ -7,7 +7,7 @@ var uiActions = require('../ui/actions')
var mopidyActions = require('../mopidy/actions')
var pusherActions = require('./actions')
var lastfmActions = require('../lastfm/actions')
var geniusActions = require('../lastfm/actions')
var geniusActions = require('../genius/actions')
var spotifyActions = require('../spotify/actions')
const PusherMiddleware = (function(){

View File

@ -66,7 +66,7 @@ class Track extends React.Component{
}
// Ready to load lyrics
if (!nextProps.track.lyrics_results){
if (nextProps.genius_authorized && !nextProps.track.lyrics_results){
this.props.geniusActions.findTrackLyrics(nextProps.track);
}
}
@ -274,8 +274,9 @@ class Track extends React.Component{
<ContextMenuTrigger onTrigger={e => this.handleContextMenu(e)} />
</div>
{this.renderLyricsSelector()}
{this.renderLyrics()}
{!this.props.genius_authorized ? <p className="no-results">Want track lyrics? Authorize Genius under <Link to={global.baseURL+"settings/service/genius"}>Settings</Link>.</p> : null}
{this.props.genius_authorized ? this.renderLyricsSelector() : null}
{this.props.genius_authorized ? this.renderLyrics() : null}
</div>
)
@ -302,6 +303,7 @@ const mapStateToProps = (state, ownProps) => {
local_library_albums: state.mopidy.library_albums,
lastfm_authorized: state.lastfm.session,
spotify_authorized: state.spotify.authorization,
genius_authorized: state.genius.authorization,
mopidy_connected: state.mopidy.connected
};
}