diff options
Diffstat (limited to 'client/src/app/shared/video/video.service.ts')
-rw-r--r-- | client/src/app/shared/video/video.service.ts | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index 996202154..a51b9cab9 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts | |||
@@ -27,10 +27,11 @@ import { objectToFormData } from '@app/shared/misc/utils' | |||
27 | import { Account } from '@app/shared/account/account.model' | 27 | import { Account } from '@app/shared/account/account.model' |
28 | import { AccountService } from '@app/shared/account/account.service' | 28 | import { AccountService } from '@app/shared/account/account.service' |
29 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | 29 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
30 | import { ServerService } from '@app/core' | 30 | import { ServerService, AuthService } from '@app/core' |
31 | import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service' | 31 | import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service' |
32 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | 32 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' |
33 | import { I18n } from '@ngx-translate/i18n-polyfill' | 33 | import { I18n } from '@ngx-translate/i18n-polyfill' |
34 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' | ||
34 | 35 | ||
35 | export interface VideosProvider { | 36 | export interface VideosProvider { |
36 | getVideos (parameters: { | 37 | getVideos (parameters: { |
@@ -49,6 +50,8 @@ export class VideoService implements VideosProvider { | |||
49 | 50 | ||
50 | constructor ( | 51 | constructor ( |
51 | private authHttp: HttpClient, | 52 | private authHttp: HttpClient, |
53 | private authService: AuthService, | ||
54 | private userService: UserService, | ||
52 | private restExtractor: RestExtractor, | 55 | private restExtractor: RestExtractor, |
53 | private restService: RestService, | 56 | private restService: RestService, |
54 | private serverService: ServerService, | 57 | private serverService: ServerService, |
@@ -199,9 +202,10 @@ export class VideoService implements VideosProvider { | |||
199 | filter?: VideoFilter, | 202 | filter?: VideoFilter, |
200 | categoryOneOf?: number, | 203 | categoryOneOf?: number, |
201 | languageOneOf?: string[], | 204 | languageOneOf?: string[], |
202 | skipCount?: boolean | 205 | skipCount?: boolean, |
206 | nsfw?: boolean | ||
203 | }): Observable<ResultList<Video>> { | 207 | }): Observable<ResultList<Video>> { |
204 | const { videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount } = parameters | 208 | const { videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount, nsfw } = parameters |
205 | 209 | ||
206 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | 210 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) |
207 | 211 | ||
@@ -212,6 +216,15 @@ export class VideoService implements VideosProvider { | |||
212 | if (categoryOneOf) params = params.set('categoryOneOf', categoryOneOf + '') | 216 | if (categoryOneOf) params = params.set('categoryOneOf', categoryOneOf + '') |
213 | if (skipCount) params = params.set('skipCount', skipCount + '') | 217 | if (skipCount) params = params.set('skipCount', skipCount + '') |
214 | 218 | ||
219 | if (nsfw) { | ||
220 | params = params.set('nsfw', nsfw + '') | ||
221 | } else { | ||
222 | const nsfwPolicy = this.authService.isLoggedIn() | ||
223 | ? this.authService.getUser().nsfwPolicy | ||
224 | : this.userService.getAnonymousUser().nsfwPolicy | ||
225 | if (this.nsfwPolicyToFilter(nsfwPolicy)) params.set('nsfw', 'false') | ||
226 | } | ||
227 | |||
215 | if (languageOneOf) { | 228 | if (languageOneOf) { |
216 | for (const l of languageOneOf) { | 229 | for (const l of languageOneOf) { |
217 | params = params.append('languageOneOf[]', l) | 230 | params = params.append('languageOneOf[]', l) |
@@ -368,4 +381,8 @@ export class VideoService implements VideosProvider { | |||
368 | catchError(err => this.restExtractor.handleError(err)) | 381 | catchError(err => this.restExtractor.handleError(err)) |
369 | ) | 382 | ) |
370 | } | 383 | } |
384 | |||
385 | private nsfwPolicyToFilter (policy: NSFWPolicyType) { | ||
386 | return policy === 'do_not_list' | ||
387 | } | ||
371 | } | 388 | } |