koel/resources/assets/js/services/youTubeService.ts

29 lines
741 B
TypeScript
Raw Normal View History

2022-07-07 23:15:38 +00:00
import { Cache, httpService } from '@/services'
2022-04-15 14:24:30 +00:00
import { eventBus } from '@/utils'
import router from '@/router'
interface YouTubeSearchResult {
nextPageToken: string
items: Record<string, any>[]
2022-04-15 14:24:30 +00:00
}
2022-04-24 08:50:45 +00:00
export const youTubeService = {
2022-07-07 23:15:38 +00:00
searchVideosBySong: async (song: Song, nextPageToken: string) => {
return await Cache.resolve<YouTubeSearchResult>(
['youtube.search', song.id, nextPageToken],
async () => await httpService.get<YouTubeSearchResult>(
`youtube/search/song/${song.id}?pageToken=${nextPageToken}`
)
)
2022-04-15 14:24:30 +00:00
},
play: (video: YouTubeVideo): void => {
eventBus.emit('PLAY_YOUTUBE_VIDEO', {
id: video.id.videoId,
title: video.snippet.title
})
router.go('youtube')
}
}