aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search/search.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/search/search.service.ts')
-rw-r--r--client/src/app/search/search.service.ts48
1 files changed, 32 insertions, 16 deletions
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts
index 3cad5aaa7..fdb12ea2c 100644
--- a/client/src/app/search/search.service.ts
+++ b/client/src/app/search/search.service.ts
@@ -1,17 +1,18 @@
1import { Observable } from 'rxjs'
1import { catchError, map, switchMap } from 'rxjs/operators' 2import { catchError, map, switchMap } from 'rxjs/operators'
2import { HttpClient, HttpParams } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
3import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
4import { Observable } from 'rxjs'
5import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model'
6import { VideoService } from '@app/shared/video/video.service'
7import { RestExtractor, RestService } from '@app/shared'
8import { environment } from '../../environments/environment'
9import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared'
10import { Video } from '@app/shared/video/video.model'
11import { AdvancedSearch } from '@app/search/advanced-search.model' 5import { AdvancedSearch } from '@app/search/advanced-search.model'
6import { RestExtractor, RestPagination, RestService } from '@app/shared'
7import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
8import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model'
12import { VideoChannel } from '@app/shared/video-channel/video-channel.model' 9import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
13import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' 10import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
14import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' 11import { Video } from '@app/shared/video/video.model'
12import { VideoService } from '@app/shared/video/video.service'
13import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared'
14import { environment } from '../../environments/environment'
15import { SearchTargetType } from '@shared/models/search/search-target-query.model'
15 16
16@Injectable() 17@Injectable()
17export class SearchService { 18export class SearchService {
@@ -30,21 +31,27 @@ export class SearchService {
30 31
31 searchVideos (parameters: { 32 searchVideos (parameters: {
32 search: string, 33 search: string,
33 componentPagination: ComponentPaginationLight, 34 componentPagination?: ComponentPaginationLight,
34 advancedSearch: AdvancedSearch 35 advancedSearch?: AdvancedSearch
35 }): Observable<ResultList<Video>> { 36 }): Observable<ResultList<Video>> {
36 const { search, componentPagination, advancedSearch } = parameters 37 const { search, componentPagination, advancedSearch } = parameters
37 38
38 const url = SearchService.BASE_SEARCH_URL + 'videos' 39 const url = SearchService.BASE_SEARCH_URL + 'videos'
39 const pagination = this.restService.componentPaginationToRestPagination(componentPagination) 40 let pagination: RestPagination
41
42 if (componentPagination) {
43 pagination = this.restService.componentPaginationToRestPagination(componentPagination)
44 }
40 45
41 let params = new HttpParams() 46 let params = new HttpParams()
42 params = this.restService.addRestGetParams(params, pagination) 47 params = this.restService.addRestGetParams(params, pagination)
43 48
44 if (search) params = params.append('search', search) 49 if (search) params = params.append('search', search)
45 50
46 const advancedSearchObject = advancedSearch.toAPIObject() 51 if (advancedSearch) {
47 params = this.restService.addObjectParams(params, advancedSearchObject) 52 const advancedSearchObject = advancedSearch.toAPIObject()
53 params = this.restService.addObjectParams(params, advancedSearchObject)
54 }
48 55
49 return this.authHttp 56 return this.authHttp
50 .get<ResultList<VideoServerModel>>(url, { params }) 57 .get<ResultList<VideoServerModel>>(url, { params })
@@ -56,17 +63,26 @@ export class SearchService {
56 63
57 searchVideoChannels (parameters: { 64 searchVideoChannels (parameters: {
58 search: string, 65 search: string,
59 componentPagination: ComponentPaginationLight 66 searchTarget?: SearchTargetType,
67 componentPagination?: ComponentPaginationLight
60 }): Observable<ResultList<VideoChannel>> { 68 }): Observable<ResultList<VideoChannel>> {
61 const { search, componentPagination } = parameters 69 const { search, componentPagination, searchTarget } = parameters
62 70
63 const url = SearchService.BASE_SEARCH_URL + 'video-channels' 71 const url = SearchService.BASE_SEARCH_URL + 'video-channels'
64 const pagination = this.restService.componentPaginationToRestPagination(componentPagination) 72
73 let pagination: RestPagination
74 if (componentPagination) {
75 pagination = this.restService.componentPaginationToRestPagination(componentPagination)
76 }
65 77
66 let params = new HttpParams() 78 let params = new HttpParams()
67 params = this.restService.addRestGetParams(params, pagination) 79 params = this.restService.addRestGetParams(params, pagination)
68 params = params.append('search', search) 80 params = params.append('search', search)
69 81
82 if (searchTarget) {
83 params = params.append('searchTarget', searchTarget as string)
84 }
85
70 return this.authHttp 86 return this.authHttp
71 .get<ResultList<VideoChannelServerModel>>(url, { params }) 87 .get<ResultList<VideoChannelServerModel>>(url, { params })
72 .pipe( 88 .pipe(