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, VideoPrivacy } from '@shared/models'
9 import { getAllPrivacies } from '@shared/core-utils'
12 export class VideoAdminService {
15 private videoService: VideoService,
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor,
18 private restService: RestService
22 options: CommonVideoParams & { pagination: RestPagination, search?: string }
23 ): Observable<ResultList<Video>> {
24 const { pagination, search } = options
26 let params = new HttpParams()
27 params = this.videoService.buildCommonVideosParams({ params, ...options })
29 params = params.set('start', pagination.start.toString())
30 .set('count', pagination.count.toString())
32 params = this.buildAdminParamsFromSearch(search, params)
35 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
37 switchMap(res => this.videoService.extractVideos(res)),
38 catchError(err => this.restExtractor.handleError(err))
42 buildAdminInputFilter (): AdvancedInputFilter[] {
45 title: $localize`Video type`,
48 value: 'isLive:false',
53 label: $localize`Live`
59 title: $localize`Video files`,
62 value: 'webtorrent:true isLocal:true',
63 label: $localize`With WebTorrent`
66 value: 'webtorrent:false isLocal:true',
67 label: $localize`Without WebTorrent`
70 value: 'hls:true isLocal:true',
71 label: $localize`With HLS`
74 value: 'hls:false isLocal:true',
75 label: $localize`Without HLS`
81 title: $localize`Videos scope`,
84 value: 'isLocal:false',
85 label: $localize`Remote videos`
88 value: 'isLocal:true',
89 label: $localize`Local videos`
95 title: $localize`Exclude`,
98 value: 'excludeMuted',
99 label: $localize`Exclude muted accounts`
102 value: 'excludePublic',
103 label: $localize`Exclude public videos`
110 private buildAdminParamsFromSearch (search: string, params: HttpParams) {
111 let include = VideoInclude.BLACKLISTED |
112 VideoInclude.BLOCKED_OWNER |
113 VideoInclude.NOT_PUBLISHED_STATE |
116 let privacyOneOf = getAllPrivacies()
118 if (!search) return this.restService.addObjectParams(params, { include, privacyOneOf })
120 const filters = this.restService.parseQueryStringFilter(search, {
129 hasWebtorrentFiles: {
130 prefix: 'webtorrent:',
138 prefix: 'excludeMuted',
142 prefix: 'excludePublic',
147 if (filters.excludeMuted) {
148 include &= ~VideoInclude.BLOCKED_OWNER
150 filters.excludeMuted = undefined
153 if (filters.excludePublic) {
154 privacyOneOf = [ VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED, VideoPrivacy.INTERNAL ]
156 filters.excludePublic = undefined
159 return this.restService.addObjectParams(params, { ...filters, include, privacyOneOf })