diff options
Diffstat (limited to 'client/src/app/search/search.service.ts')
-rw-r--r-- | client/src/app/search/search.service.ts | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts deleted file mode 100644 index 36342034f..000000000 --- a/client/src/app/search/search.service.ts +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | import { Observable } from 'rxjs' | ||
2 | import { catchError, map, switchMap } from 'rxjs/operators' | ||
3 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
4 | import { Injectable } from '@angular/core' | ||
5 | import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core' | ||
6 | import { peertubeLocalStorage } from '@app/helpers' | ||
7 | import { AdvancedSearch } from '@app/search/advanced-search.model' | ||
8 | import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' | ||
9 | import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '@shared/models' | ||
10 | import { SearchTargetType } from '@shared/models/search/search-target-query.model' | ||
11 | import { environment } from '../../environments/environment' | ||
12 | |||
13 | @Injectable() | ||
14 | export class SearchService { | ||
15 | static BASE_SEARCH_URL = environment.apiUrl + '/api/v1/search/' | ||
16 | |||
17 | constructor ( | ||
18 | private authHttp: HttpClient, | ||
19 | private restExtractor: RestExtractor, | ||
20 | private restService: RestService, | ||
21 | private videoService: VideoService | ||
22 | ) { | ||
23 | // Add ability to override search endpoint if the user updated this local storage key | ||
24 | const searchUrl = peertubeLocalStorage.getItem('search-url') | ||
25 | if (searchUrl) SearchService.BASE_SEARCH_URL = searchUrl | ||
26 | } | ||
27 | |||
28 | searchVideos (parameters: { | ||
29 | search: string, | ||
30 | componentPagination?: ComponentPaginationLight, | ||
31 | advancedSearch?: AdvancedSearch | ||
32 | }): Observable<ResultList<Video>> { | ||
33 | const { search, componentPagination, advancedSearch } = parameters | ||
34 | |||
35 | const url = SearchService.BASE_SEARCH_URL + 'videos' | ||
36 | let pagination: RestPagination | ||
37 | |||
38 | if (componentPagination) { | ||
39 | pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
40 | } | ||
41 | |||
42 | let params = new HttpParams() | ||
43 | params = this.restService.addRestGetParams(params, pagination) | ||
44 | |||
45 | if (search) params = params.append('search', search) | ||
46 | |||
47 | if (advancedSearch) { | ||
48 | const advancedSearchObject = advancedSearch.toAPIObject() | ||
49 | params = this.restService.addObjectParams(params, advancedSearchObject) | ||
50 | } | ||
51 | |||
52 | return this.authHttp | ||
53 | .get<ResultList<VideoServerModel>>(url, { params }) | ||
54 | .pipe( | ||
55 | switchMap(res => this.videoService.extractVideos(res)), | ||
56 | catchError(err => this.restExtractor.handleError(err)) | ||
57 | ) | ||
58 | } | ||
59 | |||
60 | searchVideoChannels (parameters: { | ||
61 | search: string, | ||
62 | searchTarget?: SearchTargetType, | ||
63 | componentPagination?: ComponentPaginationLight | ||
64 | }): Observable<ResultList<VideoChannel>> { | ||
65 | const { search, componentPagination, searchTarget } = parameters | ||
66 | |||
67 | const url = SearchService.BASE_SEARCH_URL + 'video-channels' | ||
68 | |||
69 | let pagination: RestPagination | ||
70 | if (componentPagination) { | ||
71 | pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
72 | } | ||
73 | |||
74 | let params = new HttpParams() | ||
75 | params = this.restService.addRestGetParams(params, pagination) | ||
76 | params = params.append('search', search) | ||
77 | |||
78 | if (searchTarget) { | ||
79 | params = params.append('searchTarget', searchTarget as string) | ||
80 | } | ||
81 | |||
82 | return this.authHttp | ||
83 | .get<ResultList<VideoChannelServerModel>>(url, { params }) | ||
84 | .pipe( | ||
85 | map(res => VideoChannelService.extractVideoChannels(res)), | ||
86 | catchError(err => this.restExtractor.handleError(err)) | ||
87 | ) | ||
88 | } | ||
89 | } | ||