Mopidy image processing and absolut-ing in one
This commit is contained in:
@ -87,31 +87,41 @@ export let sizedImages = function(images){
|
||||
|
||||
|
||||
/**
|
||||
* Digest an array of Mopidy image objects into a universal format
|
||||
* Digest an array of Mopidy image objects into a universal format. We also re-write
|
||||
* image URLs to be absolute to the mopidy server (required for proxy setups).
|
||||
*
|
||||
* @param mopidy = obj (mopidy store object)
|
||||
* @param images = array
|
||||
* @return array
|
||||
**/
|
||||
export let digestMopidyImages = function(mopidy, images){
|
||||
let digested = []
|
||||
var digested = [];
|
||||
|
||||
for (let i = 0; i < images.length; i++){
|
||||
for (var i = 0; i < images.length; i++){
|
||||
|
||||
// Accommodate backends that provide URIs vs URLs
|
||||
let url = images[i].url
|
||||
if (!url && images[i].uri){
|
||||
url = images[i].uri
|
||||
// Image object (ie from images.get)
|
||||
if (typeof images[i] === 'object'){
|
||||
// Accommodate backends that provide URIs vs URLs
|
||||
var url = images[i].url
|
||||
if (!url && images[i].uri){
|
||||
url = images[i].uri
|
||||
}
|
||||
|
||||
// Amend our URL
|
||||
images[i].url = url
|
||||
|
||||
// Replace local images to point directly to our Mopidy server
|
||||
if (url.startsWith('/images/')){
|
||||
url = '//'+mopidy.host+':'+mopidy.port+url
|
||||
}
|
||||
|
||||
// String-based image
|
||||
} else if (typeof images[i] === 'string'){
|
||||
// Replace local images to point directly to our Mopidy server
|
||||
if (images[i].startsWith('/images/')){
|
||||
images[i] = '//'+mopidy.host+':'+mopidy.port+images[i]
|
||||
}
|
||||
}
|
||||
/*
|
||||
// Replace local images to point directly to our Mopidy server
|
||||
if (url.startsWith('/images/')){
|
||||
url = '//'+mopidy.host+':'+mopidy.port+url
|
||||
}
|
||||
*/
|
||||
|
||||
// Amend our URL
|
||||
images[i].url = url
|
||||
|
||||
digested.push(images[i])
|
||||
}
|
||||
|
||||
@ -77,8 +77,19 @@ const CoreMiddleware = (function(){
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'TRACK_LOADED':
|
||||
if (action.data) ReactGA.event({ category: 'Track', action: 'Load', label: action.key });
|
||||
|
||||
// make sure our images use mopidy host:port
|
||||
if (action.track.album && action.track.album.images && action.track.album.images.length > 0){
|
||||
action.track.album.images = helpers.digestMopidyImages(store.getState().mopidy, action.track.album.images);
|
||||
}
|
||||
|
||||
next(action)
|
||||
break
|
||||
|
||||
case 'ALBUM_LOADED':
|
||||
if (action.data) ReactGA.event({ category: 'Album', action: 'Load', label: action.album.uri })
|
||||
if (action.data) ReactGA.event({ category: 'Album', action: 'Load', label: action.key })
|
||||
|
||||
// make sure our images use mopidy host:port
|
||||
if (action.album.images && action.album.images.length > 0){
|
||||
@ -98,6 +109,7 @@ const CoreMiddleware = (function(){
|
||||
if (action.data) ReactGA.event({ category: 'Albums', action: 'Load', label: action.albums.length+' items' })
|
||||
|
||||
for (var i = 0; i < action.albums.length; i++){
|
||||
|
||||
// make sure our images use mopidy host:port
|
||||
if (action.albums[i].images && action.albums[i].images.length > 0){
|
||||
var images = Object.assign([], action.albums[i].images)
|
||||
|
||||
Reference in New Issue
Block a user