koel/resources/assets/js/services/info/songInfoService.ts
2022-05-14 20:49:45 +02:00

32 lines
784 B
TypeScript

import { albumInfoService, artistInfoService, httpService } from '@/services'
interface SongInfoResponse {
artist_info: ArtistInfo,
album_info: AlbumInfo,
youtube: {
items: YouTubeVideo[],
nextPageToken: string
},
lyrics: string
}
export const songInfoService = {
fetch: async (song: Song) => {
if (!song.infoRetrieved) {
const {
lyrics,
artist_info: artistInfo,
album_info: albumInfo,
youtube
} = await httpService.get<SongInfoResponse>(`song/${song.id}/info`)
song.lyrics = lyrics
artistInfo && artistInfoService.merge(song.artist, artistInfo)
albumInfo && albumInfoService.merge(song.album, albumInfo)
song.youtube = youtube
song.infoRetrieved = true
}
return song
}
}