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

33 lines
776 B
TypeScript
Raw Normal View History

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