mirror of
https://github.com/koel/koel
synced 2024-12-21 01:53:11 +00:00
32 lines
725 B
TypeScript
32 lines
725 B
TypeScript
import { httpService } from '@/services'
|
|
|
|
export const artistInfoService = {
|
|
async fetch (artist: Artist) {
|
|
if (!artist.info) {
|
|
const info = await httpService.get<ArtistInfo | null>(`artist/${artist.id}/info`)
|
|
|
|
if (info) {
|
|
this.merge(artist, info)
|
|
}
|
|
}
|
|
|
|
return artist
|
|
},
|
|
|
|
/**
|
|
* Merge the (fetched) info into an artist.
|
|
*/
|
|
merge: (artist: Artist, info: ArtistInfo) => {
|
|
// If the artist image is not in a nice form, discard.
|
|
if (typeof info.image !== 'string') {
|
|
info.image = null
|
|
}
|
|
|
|
// Set the artist image on the client side to the retrieved image from server.
|
|
if (info.image) {
|
|
artist.image = info.image
|
|
}
|
|
|
|
artist.info = info
|
|
}
|
|
}
|