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

26 lines
669 B
TypeScript
Raw Normal View History

import { cache, http } from '@/services'
2022-04-15 14:24:30 +00:00
import { eventBus } from '@/utils'
interface YouTubeSearchResult {
nextPageToken: string
2022-07-22 15:03:45 +00:00
items: YouTubeVideo[]
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) => {
2022-07-25 13:25:27 +00:00
return await cache.remember<YouTubeSearchResult>(
2022-07-07 23:15:38 +00:00
['youtube.search', song.id, nextPageToken],
async () => await http.get<YouTubeSearchResult>(
`youtube/search/song/${song.id}?pageToken=${nextPageToken}`,
),
2022-07-07 23:15:38 +00:00
)
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,
2022-04-15 14:24:30 +00:00
})
},
2022-04-15 14:24:30 +00:00
}