1 import { Observable } from 'rxjs'
2 import { catchError, switchMap } from 'rxjs/operators'
3 import { HttpClient, HttpParams } from '@angular/common/http'
4 import { Injectable } from '@angular/core'
5 import { RestExtractor, RestPagination, RestService } from '@app/core'
6 import { AdvancedInputFilter } from '@app/shared/shared-forms'
7 import { CommonVideoParams, Video, VideoService } from '@app/shared/shared-main'
8 import { ResultList, VideoInclude } from '@shared/models'
11 export class VideoAdminService {
14 private videoService: VideoService,
15 private authHttp: HttpClient,
16 private restExtractor: RestExtractor,
17 private restService: RestService
21 options: CommonVideoParams & { pagination: RestPagination, search?: string }
22 ): Observable<ResultList<Video>> {
23 const { pagination, search } = options
25 let params = new HttpParams()
26 params = this.videoService.buildCommonVideosParams({ params, ...options })
28 params = params.set('start', pagination.start.toString())
29 .set('count', pagination.count.toString())
31 params = this.buildAdminParamsFromSearch(search, params)
34 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
36 switchMap(res => this.videoService.extractVideos(res)),
37 catchError(err => this.restExtractor.handleError(err))
41 buildAdminInputFilter (): AdvancedInputFilter[] {
44 title: $localize`Videos scope`,
47 queryParams: { search: 'isLocal:false' },
48 label: $localize`Remote videos`
51 queryParams: { search: 'isLocal:true' },
52 label: $localize`Local videos`
58 title: $localize`Include/Exclude`,
61 queryParams: { search: 'excludeMuted' },
62 label: $localize`Exclude muted accounts`
69 private buildAdminParamsFromSearch (search: string, params: HttpParams) {
70 let include = VideoInclude.BLACKLISTED |
71 VideoInclude.BLOCKED_OWNER |
72 VideoInclude.HIDDEN_PRIVACY |
73 VideoInclude.NOT_PUBLISHED_STATE |
76 if (!search) return this.restService.addObjectParams(params, { include })
78 const filters = this.restService.parseQueryStringFilter(search, {
84 prefix: 'excludeMuted',
89 if (filters.excludeMuted) {
90 include &= ~VideoInclude.BLOCKED_OWNER
92 filters.excludeMuted = undefined
95 return this.restService.addObjectParams(params, { ...filters, include })