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`Video type`,
47 queryParams: { search: 'isLive:false' },
51 queryParams: { search: 'isLive:true' },
52 label: $localize`Live`
58 title: $localize`Video files`,
61 queryParams: { search: 'webtorrent:true' },
62 label: $localize`With WebTorrent`
65 queryParams: { search: 'webtorrent:false' },
66 label: $localize`Without WebTorrent`
69 queryParams: { search: 'hls:true' },
70 label: $localize`With HLS`
73 queryParams: { search: 'hls:false' },
74 label: $localize`Without HLS`
80 title: $localize`Videos scope`,
83 queryParams: { search: 'isLocal:false' },
84 label: $localize`Remote videos`
87 queryParams: { search: 'isLocal:true' },
88 label: $localize`Local videos`
94 title: $localize`Exclude`,
97 queryParams: { search: 'excludeMuted' },
98 label: $localize`Exclude muted accounts`
105 private buildAdminParamsFromSearch (search: string, params: HttpParams) {
106 let include = VideoInclude.BLACKLISTED |
107 VideoInclude.BLOCKED_OWNER |
108 VideoInclude.HIDDEN_PRIVACY |
109 VideoInclude.NOT_PUBLISHED_STATE |
112 if (!search) return this.restService.addObjectParams(params, { include })
114 const filters = this.restService.parseQueryStringFilter(search, {
123 hasWebtorrentFiles: {
124 prefix: 'webtorrent:',
132 prefix: 'excludeMuted',
137 if (filters.excludeMuted) {
138 include &= ~VideoInclude.BLOCKED_OWNER
140 filters.excludeMuted = undefined
143 return this.restService.addObjectParams(params, { ...filters, include })