koel/resources/assets/js/services/info/artistInfoService.ts

33 lines
725 B
TypeScript
Raw Normal View History

2022-05-14 18:49:45 +00:00
import { httpService } from '@/services'
2022-04-15 14:24:30 +00:00
2022-04-24 08:50:45 +00:00
export const artistInfoService = {
2022-05-14 18:49:45 +00:00
async fetch (artist: Artist) {
2022-04-15 14:24:30 +00:00
if (!artist.info) {
2022-05-14 18:49:45 +00:00
const info = await httpService.get<ArtistInfo | null>(`artist/${artist.id}/info`)
2022-04-15 14:24:30 +00:00
if (info) {
this.merge(artist, info)
}
}
return artist
},
/**
* Merge the (fetched) info into an artist.
*/
2022-05-14 18:49:45 +00:00
merge: (artist: Artist, info: ArtistInfo) => {
2022-04-15 14:24:30 +00:00
// 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
}
}