]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/videos/video-admin.service.ts
Add ability to filter out public videos from admin
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / videos / video-admin.service.ts
CommitLineData
05ac4ac7
C
1import { Observable } from 'rxjs'
2import { catchError, switchMap } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core'
5import { RestExtractor, RestPagination, RestService } from '@app/core'
6import { AdvancedInputFilter } from '@app/shared/shared-forms'
7import { CommonVideoParams, Video, VideoService } from '@app/shared/shared-main'
527a52ac
C
8import { ResultList, VideoInclude, VideoPrivacy } from '@shared/models'
9import { getAllPrivacies } from '@shared/core-utils'
05ac4ac7
C
10
11@Injectable()
12export class VideoAdminService {
13
14 constructor (
15 private videoService: VideoService,
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor,
18 private restService: RestService
19 ) {}
20
21 getAdminVideos (
22 options: CommonVideoParams & { pagination: RestPagination, search?: string }
23 ): Observable<ResultList<Video>> {
24 const { pagination, search } = options
25
26 let params = new HttpParams()
27 params = this.videoService.buildCommonVideosParams({ params, ...options })
28
29 params = params.set('start', pagination.start.toString())
30 .set('count', pagination.count.toString())
31
32 params = this.buildAdminParamsFromSearch(search, params)
33
34 return this.authHttp
35 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
36 .pipe(
37 switchMap(res => this.videoService.extractVideos(res)),
38 catchError(err => this.restExtractor.handleError(err))
39 )
40 }
41
42 buildAdminInputFilter (): AdvancedInputFilter[] {
43 return [
d5d9c5b7
C
44 {
45 title: $localize`Video type`,
46 children: [
47 {
dd6d2a7c 48 value: 'isLive:false',
d324756e 49 label: $localize`VOD`
d5d9c5b7
C
50 },
51 {
dd6d2a7c 52 value: 'isLive:true',
d324756e
C
53 label: $localize`Live`
54 }
55 ]
56 },
57
58 {
59 title: $localize`Video files`,
60 children: [
61 {
dd6d2a7c 62 value: 'webtorrent:true',
d324756e
C
63 label: $localize`With WebTorrent`
64 },
65 {
dd6d2a7c 66 value: 'webtorrent:false',
d324756e
C
67 label: $localize`Without WebTorrent`
68 },
69 {
dd6d2a7c 70 value: 'hls:true',
d324756e
C
71 label: $localize`With HLS`
72 },
73 {
dd6d2a7c 74 value: 'hls:false',
d324756e 75 label: $localize`Without HLS`
d5d9c5b7
C
76 }
77 ]
78 },
79
05ac4ac7
C
80 {
81 title: $localize`Videos scope`,
82 children: [
83 {
dd6d2a7c 84 value: 'isLocal:false',
05ac4ac7
C
85 label: $localize`Remote videos`
86 },
87 {
dd6d2a7c 88 value: 'isLocal:true',
05ac4ac7
C
89 label: $localize`Local videos`
90 }
91 ]
92 },
93
94 {
d324756e 95 title: $localize`Exclude`,
05ac4ac7
C
96 children: [
97 {
dd6d2a7c 98 value: 'excludeMuted',
05ac4ac7 99 label: $localize`Exclude muted accounts`
527a52ac
C
100 },
101 {
102 value: 'excludePublic',
103 label: $localize`Exclude public videos`
05ac4ac7
C
104 }
105 ]
106 }
107 ]
108 }
109
110 private buildAdminParamsFromSearch (search: string, params: HttpParams) {
111 let include = VideoInclude.BLACKLISTED |
112 VideoInclude.BLOCKED_OWNER |
05ac4ac7
C
113 VideoInclude.NOT_PUBLISHED_STATE |
114 VideoInclude.FILES
115
527a52ac
C
116 let privacyOneOf = getAllPrivacies()
117
118 if (!search) return this.restService.addObjectParams(params, { include, privacyOneOf })
05ac4ac7
C
119
120 const filters = this.restService.parseQueryStringFilter(search, {
121 isLocal: {
122 prefix: 'isLocal:',
123 isBoolean: true
124 },
d324756e
C
125 hasHLSFiles: {
126 prefix: 'hls:',
127 isBoolean: true
128 },
129 hasWebtorrentFiles: {
130 prefix: 'webtorrent:',
131 isBoolean: true
132 },
d5d9c5b7
C
133 isLive: {
134 prefix: 'isLive:',
135 isBoolean: true
136 },
05ac4ac7
C
137 excludeMuted: {
138 prefix: 'excludeMuted',
139 handler: () => true
527a52ac
C
140 },
141 excludePublic: {
142 prefix: 'excludePublic',
143 handler: () => true
05ac4ac7
C
144 }
145 })
146
147 if (filters.excludeMuted) {
148 include &= ~VideoInclude.BLOCKED_OWNER
149
150 filters.excludeMuted = undefined
151 }
152
527a52ac
C
153 if (filters.excludePublic) {
154 privacyOneOf = [ VideoPrivacy.PRIVATE, VideoPrivacy.UNLISTED, VideoPrivacy.INTERNAL ]
155
156 filters.excludePublic = undefined
157 }
158
159 return this.restService.addObjectParams(params, { ...filters, include, privacyOneOf })
05ac4ac7
C
160 }
161}