aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-search
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-search')
-rw-r--r--client/src/app/shared/shared-search/search.service.ts44
1 files changed, 41 insertions, 3 deletions
diff --git a/client/src/app/shared/shared-search/search.service.ts b/client/src/app/shared/shared-search/search.service.ts
index 15c4a7012..ad258f5e5 100644
--- a/client/src/app/shared/shared-search/search.service.ts
+++ b/client/src/app/shared/shared-search/search.service.ts
@@ -3,10 +3,17 @@ import { catchError, map, switchMap } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core' 5import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core'
6import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
7import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' 6import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
8import { ResultList, SearchTargetType, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '@shared/models' 7import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
8import {
9 ResultList,
10 SearchTargetType,
11 Video as VideoServerModel,
12 VideoChannel as VideoChannelServerModel,
13 VideoPlaylist as VideoPlaylistServerModel
14} from '@shared/models'
9import { environment } from '../../../environments/environment' 15import { environment } from '../../../environments/environment'
16import { VideoPlaylist, VideoPlaylistService } from '../shared-video-playlist'
10import { AdvancedSearch } from './advanced-search.model' 17import { AdvancedSearch } from './advanced-search.model'
11 18
12@Injectable() 19@Injectable()
@@ -17,7 +24,8 @@ export class SearchService {
17 private authHttp: HttpClient, 24 private authHttp: HttpClient,
18 private restExtractor: RestExtractor, 25 private restExtractor: RestExtractor,
19 private restService: RestService, 26 private restService: RestService,
20 private videoService: VideoService 27 private videoService: VideoService,
28 private playlistService: VideoPlaylistService
21 ) { 29 ) {
22 // Add ability to override search endpoint if the user updated this local storage key 30 // Add ability to override search endpoint if the user updated this local storage key
23 const searchUrl = peertubeLocalStorage.getItem('search-url') 31 const searchUrl = peertubeLocalStorage.getItem('search-url')
@@ -85,4 +93,34 @@ export class SearchService {
85 catchError(err => this.restExtractor.handleError(err)) 93 catchError(err => this.restExtractor.handleError(err))
86 ) 94 )
87 } 95 }
96
97 searchVideoPlaylists (parameters: {
98 search: string,
99 searchTarget?: SearchTargetType,
100 componentPagination?: ComponentPaginationLight
101 }): Observable<ResultList<VideoPlaylist>> {
102 const { search, componentPagination, searchTarget } = parameters
103
104 const url = SearchService.BASE_SEARCH_URL + 'video-playlists'
105
106 let pagination: RestPagination
107 if (componentPagination) {
108 pagination = this.restService.componentPaginationToRestPagination(componentPagination)
109 }
110
111 let params = new HttpParams()
112 params = this.restService.addRestGetParams(params, pagination)
113 params = params.append('search', search)
114
115 if (searchTarget) {
116 params = params.append('searchTarget', searchTarget as string)
117 }
118
119 return this.authHttp
120 .get<ResultList<VideoPlaylistServerModel>>(url, { params })
121 .pipe(
122 switchMap(res => this.playlistService.extractPlaylists(res)),
123 catchError(err => this.restExtractor.handleError(err))
124 )
125 }
88} 126}