koel/resources/assets/js/services/info/artist.js

43 lines
888 B
JavaScript
Raw Normal View History

2016-11-26 03:25:35 +00:00
import { http } from '..'
2016-06-05 11:29:49 +00:00
2016-06-25 10:15:57 +00:00
export const artistInfo = {
2016-06-25 16:05:24 +00:00
/**
* Get extra artist info (from Last.fm).
*
* @param {Object} artist
*/
2016-11-26 03:25:35 +00:00
fetch (artist) {
2016-06-27 06:11:35 +00:00
return new Promise((resolve, reject) => {
if (artist.info) {
2016-11-26 03:25:35 +00:00
resolve(artist)
return
2016-06-25 16:05:24 +00:00
}
2016-06-05 11:29:49 +00:00
http.get(`artist/${artist.id}/info`, data => {
2016-11-26 03:25:35 +00:00
data && this.merge(artist, data)
resolve(artist)
}, r => reject(r))
})
2016-06-25 16:05:24 +00:00
},
2016-06-05 11:29:49 +00:00
2016-06-25 16:05:24 +00:00
/**
* Merge the (fetched) info into an artist.
*
* @param {Object} artist
* @param {Object} info
*/
2016-11-26 03:25:35 +00:00
merge (artist, info) {
2016-06-25 16:05:24 +00:00
// If the artist image is not in a nice form, discard.
if (typeof info.image !== 'string') {
2016-11-26 03:25:35 +00:00
info.image = null
2016-06-25 16:05:24 +00:00
}
2016-06-05 11:29:49 +00:00
2016-06-25 16:05:24 +00:00
// Set the artist image on the client side to the retrieved image from server.
if (info.image) {
2016-11-26 03:25:35 +00:00
artist.image = info.image
2016-06-25 16:05:24 +00:00
}
2016-06-05 11:29:49 +00:00
2016-11-26 03:25:35 +00:00
artist.info = info
}
}