Preparing for production release

This commit is contained in:
James Barnsley
2020-01-22 21:21:49 +13:00
parent f581d683bc
commit e0724cedf7
8 changed files with 19635 additions and 27657 deletions

View File

@ -161,7 +161,7 @@ export function getTrackLyrics(uri, path) {
let lyrics = html.find('.lyrics');
if (lyrics.length > 0) {
lyrics = lyrics.first();
lyrics.find('a').replaceWith((item) => item.innerHTML);
lyrics.find('a').replaceWith((k, v) => v);
let lyrics_html = lyrics.html();
lyrics_html = lyrics_html.replace(/(\[)/g, '<span class="mid_grey-text">[');

View File

@ -402,14 +402,14 @@ export function getPlaylists(uris, processor = null) {
export function getDirectory(uri) {
return {
type: 'MOPIDY_GET_DIRECTORY',
data: { uri },
uri,
};
}
export function getTrack(uri) {
return {
type: 'MOPIDY_GET_TRACK',
data: { uri },
uri,
};
}
@ -444,7 +444,7 @@ export function getArtists(uris, processor = null) {
export function getAlbum(uri) {
return {
type: 'MOPIDY_GET_ALBUM',
data: { uri },
uri,
};
}

View File

@ -135,7 +135,7 @@ const MopidyMiddleware = (function () {
break;
default:
// console.log('MopidyService: Unhandled message', type, message );
// console.log('MopidyService: Unhandled message', type, message );
}
};
@ -317,9 +317,9 @@ const MopidyMiddleware = (function () {
);
break;
/**
* General playback
* */
/**
* General playback
* */
case 'MOPIDY_PLAY_STATE':
store.dispatch(uiActions.setWindowTitle(null, action.play_state));
@ -606,9 +606,9 @@ const MopidyMiddleware = (function () {
break;
/**
* Advanced playback events
* */
/**
* Advanced playback events
* */
case 'MOPIDY_PLAY_PLAYLIST':
var playlist = store.getState().core.playlists[action.uri];
@ -643,7 +643,7 @@ const MopidyMiddleware = (function () {
} else {
let tracks_uris = helpers.arrayOf('uri', response.tracks);
if (action.shuffle) {
tracks_uris = helpers.shuffle(tracks_uris);
tracks_uris = helpers.shuffle(tracks_uris);
}
store.dispatch(mopidyActions.playURIs(tracks_uris, action.uri));
}
@ -695,7 +695,7 @@ const MopidyMiddleware = (function () {
} else {
let tracks_uris = helpers.arrayOf('uri', response.tracks);
if (action.shuffle) {
tracks_uris = helpers.shuffle(tracks_uris);
tracks_uris = helpers.shuffle(tracks_uris);
}
store.dispatch(mopidyActions.enqueueURIs(tracks_uris, action.uri, action.play_next, action.at_position, action.offset));
}
@ -871,9 +871,9 @@ const MopidyMiddleware = (function () {
// Shuffle/random mode
if (store.getState().mopidy.random) {
var first_uri_index = Math.floor(Math.random() * action.uris.length);
var first_uri_index = Math.floor(Math.random() * action.uris.length);
} else {
var first_uri_index = 0;
var first_uri_index = 0;
}
var first_uri = uris[first_uri_index];
@ -940,27 +940,27 @@ const MopidyMiddleware = (function () {
case 'MOPIDY_CLEAR_TRACKLIST':
request(socket, store, 'tracklist.clear')
.then(
(response) => {
store.dispatch(coreActions.clearCurrentTrack());
.then(
(response) => {
store.dispatch(coreActions.clearCurrentTrack());
store.dispatch(pusherActions.deliverBroadcast(
'notification',
{
notification: {
content: `${store.getState().pusher.username} cleared queue`,
},
},
));
},
);
store.dispatch(pusherActions.deliverBroadcast(
'notification',
{
notification: {
content: `${store.getState().pusher.username} cleared queue`,
},
},
));
},
);
break;
/**
* =============================================================== SEARCHING ============
* ======================================================================================
* */
/**
* =============================================================== SEARCHING ============
* ======================================================================================
* */
case 'MOPIDY_GET_SEARCH_RESULTS':
@ -1101,7 +1101,7 @@ const MopidyMiddleware = (function () {
);
break;
// Artists
// Artists
case 'artists':
// Quick check to see if we should be cancelling
@ -1184,7 +1184,7 @@ const MopidyMiddleware = (function () {
);
break;
// Playlists
// Playlists
case 'playlists':
// Quick check to see if we should be cancelling
@ -1241,7 +1241,7 @@ const MopidyMiddleware = (function () {
);
break;
// Tracks
// Tracks
case 'tracks':
// Quick check to see if we should be cancelling
@ -1295,7 +1295,7 @@ const MopidyMiddleware = (function () {
break;
// Search for all types
// Search for all types
case 'all':
default:
@ -1552,10 +1552,10 @@ const MopidyMiddleware = (function () {
break;
/**
* =============================================================== PLAYLIST(S) ==========
* ======================================================================================
* */
/**
* =============================================================== PLAYLIST(S) ==========
* ======================================================================================
* */
case 'MOPIDY_GET_LIBRARY_PLAYLISTS':
request(socket, store, 'playlists.asList')
@ -1585,7 +1585,7 @@ const MopidyMiddleware = (function () {
name: response.name,
uri: response.uri,
source,
provider: 'mopidy',
provider: 'mopidy',
last_modified: response.last_modified,
tracks_total: (response.tracks ? response.tracks.length : 0),
};
@ -1722,20 +1722,20 @@ const MopidyMiddleware = (function () {
request(socket, store, 'playlists.save', { playlist: mopidy_playlist })
.then((response) => {
// Overwrite our playlist with the response to our save
// This is essential to get the updated URI from Mopidy
const playlist = {
// Overwrite our playlist with the response to our save
// This is essential to get the updated URI from Mopidy
const playlist = {
...store.getState().core.playlists[action.key],
uri: response.uri,
name: response.name,
};
...store.getState().core.playlists[action.key],
uri: response.uri,
name: response.name,
};
// When we rename a playlist, the URI also changes to reflect the name change.
// We need to update our index, as well as redirect our current page URL.
if (action.key !== playlist.uri) {
// Remove old playlist (by old key/uri) from index
// By providing the new key, the old playlist gets replaced with a redirector object
// Remove old playlist (by old key/uri) from index
// By providing the new key, the old playlist gets replaced with a redirector object
store.dispatch(coreActions.removeFromIndex('playlists', action.key, playlist.uri));
}
@ -1811,10 +1811,10 @@ const MopidyMiddleware = (function () {
break;
/**
* =============================================================== ALBUM(S) =============
* ======================================================================================
* */
/**
* =============================================================== ALBUM(S) =============
* ======================================================================================
* */
case 'MOPIDY_GET_LIBRARY_ALBUMS':
var last_run = store.getState().ui.processes.MOPIDY_LIBRARY_ALBUMS_PROCESSOR;
@ -1881,31 +1881,28 @@ const MopidyMiddleware = (function () {
case 'MOPIDY_GET_ALBUMS':
request(socket, store, 'library.lookup', { uris: action.uris })
.then((response) => {
if (response.length <= 0) {
return;
}
if (!response.length) return;
const albums_loaded = [];
const artists_loaded = [];
const tracks_loaded = [];
const artists_loaded = [];
const tracks_loaded = [];
for (const uri in response) {
if (response.hasOwnProperty(uri) && response[uri].length > 0 && response[uri][0].album) {
const tracks = response[uri];
const artists_uris = [];
const artists_uris = [];
if (tracks[0].artists) {
for (const artist of response[uri][0].artists) {
for (const artist of response[uri][0].artists) {
artists_uris.push(artist.uri);
artists_loaded.push(artist);
artists_loaded.push(artist);
}
}
}
const tracks_uris = [];
for (const track of tracks) {
const tracks_uris = [];
for (const track of tracks) {
tracks_uris.push(track.uri);
tracks_loaded.push(track);
}
tracks_loaded.push(track);
}
const album = {
@ -1939,16 +1936,16 @@ const MopidyMiddleware = (function () {
break;
case 'MOPIDY_GET_ALBUM':
request(socket, store, 'library.lookup', action.data)
.then((response) => {
if (!response || response.length <= 0) {
return;
}
request(socket, store, 'library.lookup', { uris: [action.uri] })
.then((_response) => {
if (!_response) return;
const response = _response[action.uri];
if (!response || !response.length) return;
const artists = [];
if (response[0].artists) {
for (const artist of response[0].artists) {
artists.push(artist);
artists.push(artist);
}
}
@ -1976,7 +1973,7 @@ const MopidyMiddleware = (function () {
request(socket, store, 'library.lookup', { uris: album.tracks_uris })
.then((response) => {
const tracks_loaded = [];
const tracks_loaded = [];
for (const uri in response) {
if (response.hasOwnProperty(uri)) {
@ -1990,12 +1987,13 @@ const MopidyMiddleware = (function () {
break;
/**
* =============================================================== ARTIST(S) ============
* ======================================================================================
* */
/**
* =============================================================== ARTIST(S) ============
* ======================================================================================
**/
case 'MOPIDY_GET_LIBRARY_ARTISTS':
request(socket, store, 'library.browse', { uri: store.getState().mopidy.library_artists_uri })
const uri = store.getState().mopidy.library_artists_uri;
request(socket, store, 'library.browse', { uri })
.then((response) => {
if (response.length <= 0) return;
@ -2016,68 +2014,69 @@ const MopidyMiddleware = (function () {
});
break;
/**
* TODO: Fetch and process library artists
*
* We can't get specific artist artwork from Mopidy. Perhaps we fetch additional
* artist metadata via LastFM? Their API limits will make this quite slow.
case 'MOPIDY_GET_LIBRARY_ARTISTS':
/**
* TODO: Fetch and process library artists
*
* We can't get specific artist artwork from Mopidy. Perhaps we fetch additional
* artist metadata via LastFM? Their API limits will make this quite slow.
case 'MOPIDY_GET_LIBRARY_ARTISTS':
var last_run = store.getState().ui.processes.MOPIDY_LIBRARY_ARTISTS_PROCESSOR
var last_run = store.getState().ui.processes.MOPIDY_LIBRARY_ARTISTS_PROCESSOR
if (!last_run){
request(socket, store, 'library.browse', { uri: 'local:directory?type=artist' } )
.then(response => {
if (response.length <= 0) return;
if (!last_run){
request(socket, store, 'library.browse', { uri: 'local:directory?type=artist' } )
.then(response => {
if (response.length <= 0) return;
var uris = helpers.arrayOf('uri',response);
var uris = helpers.arrayOf('uri',response);
store.dispatch({
type: 'MOPIDY_LIBRARY_ARTISTS_LOADED',
uris: uris
});
store.dispatch({
type: 'MOPIDY_LIBRARY_ARTISTS_LOADED',
uris: uris
});
// Start our process to load the full album objects
store.dispatch(uiActions.startProcess('MOPIDY_LIBRARY_ARTISTS_PROCESSOR','Loading '+uris.length+' local artists', {uris: uris}));
})
// Start our process to load the full album objects
store.dispatch(uiActions.startProcess('MOPIDY_LIBRARY_ARTISTS_PROCESSOR','Loading '+uris.length+' local artists', {uris: uris}));
})
} else if (last_run.status == 'cancelled'){
store.dispatch(uiActions.resumeProcess('MOPIDY_LIBRARY_ARTISTS_PROCESSOR'))
} else if (last_run.status == 'finished'){
// TODO: do we want to force a refresh?
}
} else if (last_run.status == 'cancelled'){
store.dispatch(uiActions.resumeProcess('MOPIDY_LIBRARY_ARTISTS_PROCESSOR'))
} else if (last_run.status == 'finished'){
// TODO: do we want to force a refresh?
}
break;
break;
case 'MOPIDY_LIBRARY_ARTISTS_PROCESSOR':
if (store.getState().ui.processes['MOPIDY_LIBRARY_ARTISTS_PROCESSOR'] !== undefined){
var processor = store.getState().ui.processes['MOPIDY_LIBRARY_ARTISTS_PROCESSOR'];
case 'MOPIDY_LIBRARY_ARTISTS_PROCESSOR':
if (store.getState().ui.processes['MOPIDY_LIBRARY_ARTISTS_PROCESSOR'] !== undefined){
var processor = store.getState().ui.processes['MOPIDY_LIBRARY_ARTISTS_PROCESSOR'];
if (processor.status == 'cancelling'){
store.dispatch(uiActions.processCancelled('MOPIDY_LIBRARY_ARTISTS_PROCESSOR'));
return false;
}
}
if (processor.status == 'cancelling'){
store.dispatch(uiActions.processCancelled('MOPIDY_LIBRARY_ARTISTS_PROCESSOR'));
return false;
}
}
var uris = Object.assign([], action.data.uris)
var uris_to_load = uris.splice(0,50)
var uris = Object.assign([], action.data.uris)
var uris_to_load = uris.splice(0,50)
if (uris_to_load.length > 0){
store.dispatch(uiActions.updateProcess('MOPIDY_LIBRARY_ARTISTS_PROCESSOR', 'Loading '+uris.length+' local artists', {uris: uris}));
store.dispatch(mopidyActions.getArtists(uris_to_load, {name: 'MOPIDY_LIBRARY_ARTISTS_PROCESSOR', data: {uris: uris}}));
} else {
store.dispatch(uiActions.processFinishing('MOPIDY_LIBRARY_ARTISTS_PROCESSOR'));
}
if (uris_to_load.length > 0){
store.dispatch(uiActions.updateProcess('MOPIDY_LIBRARY_ARTISTS_PROCESSOR', 'Loading '+uris.length+' local artists', {uris: uris}));
store.dispatch(mopidyActions.getArtists(uris_to_load, {name: 'MOPIDY_LIBRARY_ARTISTS_PROCESSOR', data: {uris: uris}}));
} else {
store.dispatch(uiActions.processFinishing('MOPIDY_LIBRARY_ARTISTS_PROCESSOR'));
}
break;
* */
break;
* */
case 'MOPIDY_GET_ARTIST':
request(socket, store, 'library.lookup', { uris: [action.uri] })
.then((response) => {
console.log(response);
if (!response[action.uri] || !response[action.uri].length) return;
response = response[action.uri];
.then((_response) => {
if (!_response) return;
const response = _response[action.uri];
if (!response || !response.length) return;
const albums = [];
for (let i = 0; i < response.length; i++) {
if (response[i].album) {
@ -2117,7 +2116,7 @@ const MopidyMiddleware = (function () {
// Add our tracks and albums
artist.albums_uris = helpers.arrayOf('uri', albums),
artist.tracks = response;
artist.tracks = response;
store.dispatch(coreActions.artistLoaded(artist));
@ -2180,10 +2179,10 @@ const MopidyMiddleware = (function () {
break;
/**
* =============================================================== TRACKS ================
* ======================================================================================
* */
/**
* =============================================================== TRACKS ================
* ======================================================================================
* */
case 'MOPIDY_GET_QUEUE':
request(socket, store, 'tracklist.getTlTracks')
@ -2235,17 +2234,17 @@ const MopidyMiddleware = (function () {
});
// Now attempt to get supporting images
if (store.getState().core.tracks[track.uri] === undefined || store.getState().core.tracks[track.uri].images === undefined) {
// We've got Spotify running, and it's a spotify track - go straight to the source!
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify') {
store.dispatch(spotifyActions.getTrack(track.uri));
if (store.getState().core.tracks[track.uri] === undefined || store.getState().core.tracks[track.uri].images === undefined) {
// We've got Spotify running, and it's a spotify track - go straight to the source!
if (store.getState().spotify.enabled && helpers.uriSource(track.uri) == 'spotify') {
store.dispatch(spotifyActions.getTrack(track.uri));
// Some other source, rely on Mopidy backends to do their work
} else {
store.dispatch(mopidyActions.getImages('tracks', [track.uri]));
}
}
}
// Some other source, rely on Mopidy backends to do their work
} else {
store.dispatch(mopidyActions.getImages('tracks', [track.uri]));
}
}
}
break;
case 'MOPIDY_GET_NEXT_TRACK':
@ -2281,13 +2280,15 @@ const MopidyMiddleware = (function () {
break;
case 'MOPIDY_GET_TRACK':
request(socket, store, 'library.lookup', action.data)
request(socket, store, 'library.lookup', { uris: [action.uri] })
.then(
(response) => {
if (response.length > 0) {
const track = { ...response[0] };
store.dispatch(coreActions.trackLoaded(track));
}
(_response) => {
if (!_response) return;
const response = _response[action.uri];
if (!response || !response.length) return;
const track = { ...response[0] };
store.dispatch(coreActions.trackLoaded(track));
},
(error) => {
store.dispatch(coreActions.handleException(
@ -2299,55 +2300,55 @@ const MopidyMiddleware = (function () {
break;
/**
* =============================================================== IMAGES ===============
* ======================================================================================
* */
/**
* =============================================================== IMAGES ===============
* ======================================================================================
* */
case 'MOPIDY_GET_IMAGES':
if (action.uris) {
request(socket, store, 'library.getImages', { uris: action.uris })
.then((response) => {
const records = [];
for (const uri in response) {
if (response.hasOwnProperty(uri)) {
let images = response[uri];
images = helpers.digestMopidyImages(store.getState().mopidy, images);
if (action.uris) {
request(socket, store, 'library.getImages', { uris: action.uris })
.then((response) => {
const records = [];
for (const uri in response) {
if (response.hasOwnProperty(uri)) {
let images = response[uri];
images = helpers.digestMopidyImages(store.getState().mopidy, images);
if (images && images.length > 0) {
records.push({
uri,
images,
});
} else {
store.dispatch(lastfmActions.getImages(action.context, uri));
}
}
}
if (images && images.length > 0) {
records.push({
uri,
images,
});
} else {
store.dispatch(lastfmActions.getImages(action.context, uri));
}
}
}
const action_data = {
type: (`${action.context}_LOADED`).toUpperCase(),
};
action_data[action.context] = records;
store.dispatch(action_data);
});
const action_data = {
type: (`${action.context}_LOADED`).toUpperCase(),
};
action_data[action.context] = records;
store.dispatch(action_data);
});
}
next(action);
break;
/**
* =============================================================== LOCAL ================
* ======================================================================================
* */
/**
* =============================================================== LOCAL ================
* ======================================================================================
* */
case 'MOPIDY_GET_DIRECTORY':
store.dispatch({
type: 'MOPIDY_DIRECTORY_FLUSH',
});
request(socket, store, 'library.browse', action.data)
request(socket, store, 'library.browse', { uri: action.uri })
.then((response) => {
const tracks_uris = [];
const subdirectories = [];
@ -2397,12 +2398,12 @@ const MopidyMiddleware = (function () {
case 'MOPIDY_DIRECTORY':
if (store.getState().ui.allow_reporting && action.data) {
ReactGA.event({ category: 'Directory', action: 'Load', label: action.data.uri });
ReactGA.event({ category: 'Directory', action: 'Load', label: action.data.uri });
}
next(action);
break;
// This action is irrelevant to us, pass it on to the next middleware
// This action is irrelevant to us, pass it on to the next middleware
default:
return next(action);
}