58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import axios from 'axios'
|
|
import { ResultList, VideoPlaylistsSearchQuery } from '../../../PeerTube/shared/models'
|
|
import { VideoChannelsSearchQuery } from '../../../PeerTube/shared/models/search/video-channels-search-query.model'
|
|
import { VideosSearchQuery } from '../../../PeerTube/shared/models/search/videos-search-query.model'
|
|
import { EnhancedVideoChannel } from '../../../server/types/channel.model'
|
|
import { EnhancedPlaylist } from '../../../server/types/playlist.model'
|
|
import { EnhancedVideo } from '../../../server/types/video.model'
|
|
import { buildApiUrl } from './utils'
|
|
|
|
const baseVideosPath = '/api/v1/search/videos'
|
|
const baseVideoChannelsPath = '/api/v1/search/video-channels'
|
|
const baseVideoPlaylistsPath = '/api/v1/search/video-playlists'
|
|
|
|
function searchVideos (options: VideosSearchQuery) {
|
|
const axiosOptions = {
|
|
params: {
|
|
...options,
|
|
|
|
search: options.search || undefined
|
|
}
|
|
}
|
|
|
|
return axios.get<ResultList<EnhancedVideo>>(buildApiUrl(baseVideosPath), axiosOptions)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
function searchVideoChannels (options: VideoChannelsSearchQuery) {
|
|
const axiosOptions = {
|
|
params: {
|
|
...options,
|
|
|
|
search: options.search || undefined
|
|
}
|
|
}
|
|
|
|
return axios.get<ResultList<EnhancedVideoChannel>>(buildApiUrl(baseVideoChannelsPath), axiosOptions)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
function searchVideoPlaylists (options: VideoPlaylistsSearchQuery) {
|
|
const axiosOptions = {
|
|
params: {
|
|
...options,
|
|
|
|
search: options.search || undefined
|
|
}
|
|
}
|
|
|
|
return axios.get<ResultList<EnhancedPlaylist>>(buildApiUrl(baseVideoPlaylistsPath), axiosOptions)
|
|
.then(res => res.data)
|
|
}
|
|
|
|
export {
|
|
searchVideos,
|
|
searchVideoChannels,
|
|
searchVideoPlaylists
|
|
}
|