Leaner handling of urlencoding - only need to strip slashes; fixes #220

This commit is contained in:
James Barnsley
2017-10-26 20:36:27 +13:00
parent ddb7dba61f
commit 0596a17847
8 changed files with 45 additions and 29 deletions

View File

@ -1111,19 +1111,22 @@ const MopidyMiddleware = (function(){
{},
response,
{
uri: decodeURIComponent(response.uri),
type: 'playlist',
is_mopidy: true,
tracks: (response.tracks ? response.tracks : [] ),
tracks_total: (response.tracks ? response.tracks.length : [] )
tracks: (response.tracks ? response.tracks : []),
tracks_total: (response.tracks ? response.tracks.length : [])
}
)
// tracks? get the full track objects
if (playlist.tracks.length > 0 ) store.dispatch({
type: 'MOPIDY_RESOLVE_PLAYLIST_TRACKS',
tracks: playlist.tracks,
key: response.uri
})
if (playlist.tracks.length > 0){
store.dispatch({
type: 'MOPIDY_RESOLVE_PLAYLIST_TRACKS',
tracks: playlist.tracks,
key: playlist.uri
});
}
store.dispatch({
type: 'PLAYLIST_LOADED',
@ -1137,7 +1140,7 @@ const MopidyMiddleware = (function(){
var tracks = Object.assign([], action.tracks)
var uris = helpers.arrayOf('uri',tracks)
instruct(socket, store, 'library.lookup', { uris: uris } )
instruct(socket, store, 'library.lookup', { uris: uris })
.then(response => {
for(var uri in response){
if (response.hasOwnProperty(uri)){
@ -1595,14 +1598,20 @@ const MopidyMiddleware = (function(){
var albums = []
for(var i = 0; i < response.length; i++){
var album = response[i].album;
var album = Object.assign(
{},
response[i].album,
{
uri: decodeURIComponent(response[i].album.uri),
}
);
if (album){
function getByURI(albumToCheck){
return album.uri == albumToCheck.uri
}
var existingAlbum = albums.find(getByURI);
if (!existingAlbum){
albums.push(album)
albums.push(album);
}
}
}
@ -1621,7 +1630,8 @@ const MopidyMiddleware = (function(){
albums_uris: helpers.arrayOf('uri',albums),
tracks: response.slice(0,10)
}
)
);
artist.uri = decodeURIComponent(artist.uri);
store.dispatch({
type: 'ARTIST_LOADED',
@ -1656,6 +1666,7 @@ const MopidyMiddleware = (function(){
is_mopidy: true
}
)
artist.uri = decodeURIComponent(artist.uri);
artists.push(artist)
}
}
@ -1663,7 +1674,7 @@ const MopidyMiddleware = (function(){
store.dispatch({
type: 'ARTISTS_LOADED',
artists: artists
})
});
// Re-run any consequential processes in 100ms. This allows a small window for other
// server requests before our next batch. It's a little crude but it means the server isn't
@ -1715,7 +1726,7 @@ const MopidyMiddleware = (function(){
if (response.length > 0){
store.dispatch({
type: 'TRACK_LOADED',
key: action.data.uri,
key: decodeURIComponent(action.data.uri),
track: response[0]
});
}
@ -1742,6 +1753,7 @@ const MopidyMiddleware = (function(){
var records = []
for (var uri in response){
uri = decodeURIComponent(uri);
if (response.hasOwnProperty(uri)){
var images = response[uri];
@ -1771,8 +1783,8 @@ const MopidyMiddleware = (function(){
case 'MOPIDY_GET_DIRECTORY':
store.dispatch({ type: 'MOPIDY_DIRECTORY_LOADED', data: false })
instruct(socket, store, 'library.browse', action.data )
.then(response => {
instruct(socket, store, 'library.browse', action.data)
.then(response => {
store.dispatch({
type: 'MOPIDY_DIRECTORY_LOADED',
data: response

View File

@ -164,11 +164,12 @@ class Album extends React.Component{
**/
const mapStateToProps = (state, ownProps) => {
var uri = ownProps.params.uri;
return {
slim_mode: state.ui.slim_mode,
load_queue: state.ui.load_queue,
artists: state.core.artists,
album: (state.core.albums && typeof(state.core.albums[ownProps.params.uri]) !== 'undefined' ? state.core.albums[ownProps.params.uri] : false ),
album: (state.core.albums && state.core.albums[uri] !== undefined ? state.core.albums[uri] : false ),
albums: state.core.albums,
spotify_library_albums: state.spotify.library_albums,
local_library_albums: state.mopidy.library_albums,

View File

@ -258,10 +258,11 @@ class Artist extends React.Component{
**/
const mapStateToProps = (state, ownProps) => {
var uri = ownProps.params.uri;
return {
slim_mode: state.ui.slim_mode,
load_queue: state.ui.load_queue,
artist: (state.core.artists && typeof(state.core.artists[ownProps.params.uri]) !== 'undefined' ? state.core.artists[ownProps.params.uri] : false ),
artist: (state.core.artists && state.core.artists[uri] !== undefined ? state.core.artists[uri] : false),
artists: (state.core.artists ? state.core.artists : []),
spotify_library_artists: state.spotify.library_artists,
local_library_artists: state.mopidy.library_artists,

View File

@ -35,7 +35,7 @@ class Playlist extends React.Component{
if (nextProps.params.uri != this.props.params.uri){
this.loadPlaylist(nextProps )
}else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
if (helpers.uriSource(this.props.params.uri ) != 'spotify'){
if (helpers.uriSource(this.props.params.uri) != 'spotify'){
this.loadPlaylist(nextProps )
}
}
@ -207,8 +207,7 @@ class Playlist extends React.Component{
**/
const mapStateToProps = (state, ownProps) => {
var uri = ownProps.params.uri
uri = uri.replace(' ','%20')
var uri = ownProps.params.uri;
return {
slim_mode: state.ui.slim_mode,
load_queue: state.ui.load_queue,

View File

@ -69,7 +69,9 @@ class Queue extends React.Component{
}
var link = null
if (this.props.current_track.album.uri ) link = '/album/'+this.props.current_track.album.uri
if (this.props.current_track.album && this.props.current_track.album.uri){
link = '/album/'+this.props.current_track.album.uri;
}
return (
<Link className={this.props.radio_enabled ? 'artwork radio-enabled' : 'artwork'} to={link}>
{this.props.radio_enabled ? <img className="radio-overlay" src="assets/radio-overlay.png" /> : null}

View File

@ -229,10 +229,11 @@ class Track extends React.Component{
**/
const mapStateToProps = (state, ownProps) => {
var uri = ownProps.params.uri;
return {
slim_mode: state.ui.slim_mode,
load_queue: state.ui.load_queue,
track: (state.core.tracks && state.core.tracks[ownProps.params.uri] !== undefined ? state.core.tracks[ownProps.params.uri] : false),
track: (state.core.tracks && state.core.tracks[uri] !== undefined ? state.core.tracks[uri] : false),
tracks: state.core.tracks,
artists: state.core.artists,
albums: state.core.albums,

View File

@ -111,12 +111,13 @@ class User extends React.Component{
}
const mapStateToProps = (state, ownProps) => {
var uri = ownProps.params.uri;
return {
load_queue: state.ui.load_queue,
spotify_authorized: state.spotify.authorization,
me: state.spotify.me,
playlists: state.core.playlists,
user: (state.core.users && state.core.users[ownProps.params.uri] !== undefined ? state.core.users[ownProps.params.uri] : false),
user: (state.core.users && state.core.users[uri] !== undefined ? state.core.users[uri] : false),
users: state.core.users
};
}

View File

@ -40,11 +40,10 @@ class LibraryBrowse extends React.Component{
loadDirectory(props = this.props){
if (props.mopidy_connected){
var uri = null
if (typeof(props.params.uri) !== 'undefined'){
uri = decodeURIComponent(props.params.uri)
if (props.params.uri !== undefined){
uri = props.params.uri;
}
this.props.mopidyActions.getDirectory(uri)
this.props.mopidyActions.getDirectory(uri);
}
}
@ -73,7 +72,7 @@ class LibraryBrowse extends React.Component{
break
default:
uri = global.baseURL+"library/browse/"+encodeURIComponent(uri)
uri = global.baseURL+"library/browse/"+uri.replace(/[/]/g,'%2F')
}
folders.push(Object.assign(
@ -177,7 +176,7 @@ class LibraryBrowse extends React.Component{
grid_items.push({
name: directory.name,
link: global.baseURL+'library/browse/'+encodeURIComponent(directory.uri),
link: global.baseURL+'library/browse/'+directory.uri.replace(/[/]/g,'%2F'),
icons: directory.icons
})
}