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

26 lines
665 B
TypeScript
Raw Normal View History

import { cache, http } from '@/services'
2022-04-15 16:24:30 +02:00
import { eventBus } from '@/utils'
interface YouTubeSearchResult {
nextPageToken: string
2022-07-22 17:03:45 +02:00
items: YouTubeVideo[]
2022-04-15 16:24:30 +02:00
}
2022-04-24 11:50:45 +03:00
export const youTubeService = {
2022-07-08 01:15:38 +02:00
searchVideosBySong: async (song: Song, nextPageToken: string) => {
2022-07-25 15:25:27 +02:00
return await cache.remember<YouTubeSearchResult>(
2022-07-08 01:15:38 +02:00
['youtube.search', song.id, nextPageToken],
async () => await http.get<YouTubeSearchResult>(
2022-07-08 01:15:38 +02:00
`youtube/search/song/${song.id}?pageToken=${nextPageToken}`
)
)
2022-04-15 16:24:30 +02:00
},
play: (video: YouTubeVideo): void => {
eventBus.emit('PLAY_YOUTUBE_VIDEO', {
id: video.id.videoId,
title: video.snippet.title
})
}
}