diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-19 09:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:24:11 +0200 |
commit | dd24f1bb0a4b252e5342b251ba36853364da7b8e (patch) | |
tree | 41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/shared/shared-main/video | |
parent | 2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff) | |
download | PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip |
Add video filters to common video pages
Diffstat (limited to 'client/src/app/shared/shared-main/video')
-rw-r--r-- | client/src/app/shared/shared-main/video/video.service.ts | 110 |
1 files changed, 40 insertions, 70 deletions
diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index 60cc9d160..3481b116f 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts | |||
@@ -5,6 +5,7 @@ import { Injectable } from '@angular/core' | |||
5 | import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' | 5 | import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' |
6 | import { objectToFormData } from '@app/helpers' | 6 | import { objectToFormData } from '@app/helpers' |
7 | import { | 7 | import { |
8 | BooleanBothQuery, | ||
8 | FeedFormat, | 9 | FeedFormat, |
9 | NSFWPolicyType, | 10 | NSFWPolicyType, |
10 | ResultList, | 11 | ResultList, |
@@ -28,19 +29,21 @@ import { VideoDetails } from './video-details.model' | |||
28 | import { VideoEdit } from './video-edit.model' | 29 | import { VideoEdit } from './video-edit.model' |
29 | import { Video } from './video.model' | 30 | import { Video } from './video.model' |
30 | 31 | ||
31 | export interface VideosProvider { | 32 | export type CommonVideoParams = { |
32 | getVideos (parameters: { | 33 | videoPagination: ComponentPaginationLight |
33 | videoPagination: ComponentPaginationLight | 34 | sort: VideoSortField |
34 | sort: VideoSortField | 35 | filter?: VideoFilter |
35 | filter?: VideoFilter | 36 | categoryOneOf?: number[] |
36 | categoryOneOf?: number[] | 37 | languageOneOf?: string[] |
37 | languageOneOf?: string[] | 38 | isLive?: boolean |
38 | nsfwPolicy: NSFWPolicyType | 39 | skipCount?: boolean |
39 | }): Observable<ResultList<Video>> | 40 | // FIXME: remove? |
41 | nsfwPolicy?: NSFWPolicyType | ||
42 | nsfw?: BooleanBothQuery | ||
40 | } | 43 | } |
41 | 44 | ||
42 | @Injectable() | 45 | @Injectable() |
43 | export class VideoService implements VideosProvider { | 46 | export class VideoService { |
44 | static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' | 47 | static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/' |
45 | static BASE_FEEDS_URL = environment.apiUrl + '/feeds/videos.' | 48 | static BASE_FEEDS_URL = environment.apiUrl + '/feeds/videos.' |
46 | static BASE_SUBSCRIPTION_FEEDS_URL = environment.apiUrl + '/feeds/subscriptions.' | 49 | static BASE_SUBSCRIPTION_FEEDS_URL = environment.apiUrl + '/feeds/subscriptions.' |
@@ -144,32 +147,16 @@ export class VideoService implements VideosProvider { | |||
144 | ) | 147 | ) |
145 | } | 148 | } |
146 | 149 | ||
147 | getAccountVideos (parameters: { | 150 | getAccountVideos (parameters: CommonVideoParams & { |
148 | account: Pick<Account, 'nameWithHost'> | 151 | account: Pick<Account, 'nameWithHost'> |
149 | videoPagination: ComponentPaginationLight | ||
150 | sort: VideoSortField | ||
151 | nsfwPolicy?: NSFWPolicyType | ||
152 | videoFilter?: VideoFilter | ||
153 | search?: string | 152 | search?: string |
154 | }): Observable<ResultList<Video>> { | 153 | }): Observable<ResultList<Video>> { |
155 | const { account, videoPagination, sort, videoFilter, nsfwPolicy, search } = parameters | 154 | const { account, search } = parameters |
156 | |||
157 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | ||
158 | 155 | ||
159 | let params = new HttpParams() | 156 | let params = new HttpParams() |
160 | params = this.restService.addRestGetParams(params, pagination, sort) | 157 | params = this.buildCommonVideosParams({ params, ...parameters }) |
161 | |||
162 | if (nsfwPolicy) { | ||
163 | params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) | ||
164 | } | ||
165 | |||
166 | if (videoFilter) { | ||
167 | params = params.set('filter', videoFilter) | ||
168 | } | ||
169 | 158 | ||
170 | if (search) { | 159 | if (search) params = params.set('search', search) |
171 | params = params.set('search', search) | ||
172 | } | ||
173 | 160 | ||
174 | return this.authHttp | 161 | return this.authHttp |
175 | .get<ResultList<Video>>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params }) | 162 | .get<ResultList<Video>>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params }) |
@@ -179,27 +166,13 @@ export class VideoService implements VideosProvider { | |||
179 | ) | 166 | ) |
180 | } | 167 | } |
181 | 168 | ||
182 | getVideoChannelVideos (parameters: { | 169 | getVideoChannelVideos (parameters: CommonVideoParams & { |
183 | videoChannel: Pick<VideoChannel, 'nameWithHost'> | 170 | videoChannel: Pick<VideoChannel, 'nameWithHost'> |
184 | videoPagination: ComponentPaginationLight | ||
185 | sort: VideoSortField | ||
186 | nsfwPolicy?: NSFWPolicyType | ||
187 | videoFilter?: VideoFilter | ||
188 | }): Observable<ResultList<Video>> { | 171 | }): Observable<ResultList<Video>> { |
189 | const { videoChannel, videoPagination, sort, nsfwPolicy, videoFilter } = parameters | 172 | const { videoChannel } = parameters |
190 | |||
191 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | ||
192 | 173 | ||
193 | let params = new HttpParams() | 174 | let params = new HttpParams() |
194 | params = this.restService.addRestGetParams(params, pagination, sort) | 175 | params = this.buildCommonVideosParams({ params, ...parameters }) |
195 | |||
196 | if (nsfwPolicy) { | ||
197 | params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) | ||
198 | } | ||
199 | |||
200 | if (videoFilter) { | ||
201 | params = params.set('filter', videoFilter) | ||
202 | } | ||
203 | 176 | ||
204 | return this.authHttp | 177 | return this.authHttp |
205 | .get<ResultList<Video>>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost + '/videos', { params }) | 178 | .get<ResultList<Video>>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost + '/videos', { params }) |
@@ -209,30 +182,9 @@ export class VideoService implements VideosProvider { | |||
209 | ) | 182 | ) |
210 | } | 183 | } |
211 | 184 | ||
212 | getVideos (parameters: { | 185 | getVideos (parameters: CommonVideoParams): Observable<ResultList<Video>> { |
213 | videoPagination: ComponentPaginationLight | ||
214 | sort: VideoSortField | ||
215 | filter?: VideoFilter | ||
216 | categoryOneOf?: number[] | ||
217 | languageOneOf?: string[] | ||
218 | isLive?: boolean | ||
219 | skipCount?: boolean | ||
220 | nsfwPolicy?: NSFWPolicyType | ||
221 | }): Observable<ResultList<Video>> { | ||
222 | const { videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount, nsfwPolicy, isLive } = parameters | ||
223 | |||
224 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | ||
225 | |||
226 | let params = new HttpParams() | 186 | let params = new HttpParams() |
227 | params = this.restService.addRestGetParams(params, pagination, sort) | 187 | params = this.buildCommonVideosParams({ params, ...parameters }) |
228 | |||
229 | if (filter) params = params.set('filter', filter) | ||
230 | if (skipCount) params = params.set('skipCount', skipCount + '') | ||
231 | |||
232 | if (isLive) params = params.set('isLive', isLive) | ||
233 | if (nsfwPolicy) params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) | ||
234 | if (languageOneOf) this.restService.addArrayParams(params, 'languageOneOf', languageOneOf) | ||
235 | if (categoryOneOf) this.restService.addArrayParams(params, 'categoryOneOf', categoryOneOf) | ||
236 | 188 | ||
237 | return this.authHttp | 189 | return this.authHttp |
238 | .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params }) | 190 | .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params }) |
@@ -421,4 +373,22 @@ export class VideoService implements VideosProvider { | |||
421 | catchError(err => this.restExtractor.handleError(err)) | 373 | catchError(err => this.restExtractor.handleError(err)) |
422 | ) | 374 | ) |
423 | } | 375 | } |
376 | |||
377 | private buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) { | ||
378 | const { params, videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount, nsfwPolicy, isLive, nsfw } = options | ||
379 | |||
380 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | ||
381 | let newParams = this.restService.addRestGetParams(params, pagination, sort) | ||
382 | |||
383 | if (filter) newParams = newParams.set('filter', filter) | ||
384 | if (skipCount) newParams = newParams.set('skipCount', skipCount + '') | ||
385 | |||
386 | if (isLive) newParams = newParams.set('isLive', isLive) | ||
387 | if (nsfw) newParams = newParams.set('nsfw', nsfw) | ||
388 | if (nsfwPolicy) newParams = newParams.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) | ||
389 | if (languageOneOf) newParams = this.restService.addArrayParams(newParams, 'languageOneOf', languageOneOf) | ||
390 | if (categoryOneOf) newParams = this.restService.addArrayParams(newParams, 'categoryOneOf', categoryOneOf) | ||
391 | |||
392 | return newParams | ||
393 | } | ||
424 | } | 394 | } |