mirror of
https://github.com/koel/koel
synced 2024-12-30 06:23:05 +00:00
33 lines
717 B
TypeScript
33 lines
717 B
TypeScript
|
import { http } from '..'
|
||
|
|
||
|
export const artistInfo = {
|
||
|
async fetch (artist: Artist): Promise<Artist> {
|
||
|
if (!artist.info) {
|
||
|
const info = await http.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): void => {
|
||
|
// 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
|
||
|
}
|
||
|
}
|