]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/overview/videos/video-admin.service.ts
Improve advanced input filter
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / videos / video-admin.service.ts
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'
9
10 @Injectable()
11 export class VideoAdminService {
12
13 constructor (
14 private videoService: VideoService,
15 private authHttp: HttpClient,
16 private restExtractor: RestExtractor,
17 private restService: RestService
18 ) {}
19
20 getAdminVideos (
21 options: CommonVideoParams & { pagination: RestPagination, search?: string }
22 ): Observable<ResultList<Video>> {
23 const { pagination, search } = options
24
25 let params = new HttpParams()
26 params = this.videoService.buildCommonVideosParams({ params, ...options })
27
28 params = params.set('start', pagination.start.toString())
29 .set('count', pagination.count.toString())
30
31 params = this.buildAdminParamsFromSearch(search, params)
32
33 return this.authHttp
34 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
35 .pipe(
36 switchMap(res => this.videoService.extractVideos(res)),
37 catchError(err => this.restExtractor.handleError(err))
38 )
39 }
40
41 buildAdminInputFilter (): AdvancedInputFilter[] {
42 return [
43 {
44 title: $localize`Video type`,
45 children: [
46 {
47 value: 'isLive:false',
48 label: $localize`VOD`
49 },
50 {
51 value: 'isLive:true',
52 label: $localize`Live`
53 }
54 ]
55 },
56
57 {
58 title: $localize`Video files`,
59 children: [
60 {
61 value: 'webtorrent:true',
62 label: $localize`With WebTorrent`
63 },
64 {
65 value: 'webtorrent:false',
66 label: $localize`Without WebTorrent`
67 },
68 {
69 value: 'hls:true',
70 label: $localize`With HLS`
71 },
72 {
73 value: 'hls:false',
74 label: $localize`Without HLS`
75 }
76 ]
77 },
78
79 {
80 title: $localize`Videos scope`,
81 children: [
82 {
83 value: 'isLocal:false',
84 label: $localize`Remote videos`
85 },
86 {
87 value: 'isLocal:true',
88 label: $localize`Local videos`
89 }
90 ]
91 },
92
93 {
94 title: $localize`Exclude`,
95 children: [
96 {
97 value: 'excludeMuted',
98 label: $localize`Exclude muted accounts`
99 }
100 ]
101 }
102 ]
103 }
104
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 |
110 VideoInclude.FILES
111
112 if (!search) return this.restService.addObjectParams(params, { include })
113
114 const filters = this.restService.parseQueryStringFilter(search, {
115 isLocal: {
116 prefix: 'isLocal:',
117 isBoolean: true
118 },
119 hasHLSFiles: {
120 prefix: 'hls:',
121 isBoolean: true
122 },
123 hasWebtorrentFiles: {
124 prefix: 'webtorrent:',
125 isBoolean: true
126 },
127 isLive: {
128 prefix: 'isLive:',
129 isBoolean: true
130 },
131 excludeMuted: {
132 prefix: 'excludeMuted',
133 handler: () => true
134 }
135 })
136
137 if (filters.excludeMuted) {
138 include &= ~VideoInclude.BLOCKED_OWNER
139
140 filters.excludeMuted = undefined
141 }
142
143 return this.restService.addObjectParams(params, { ...filters, include })
144 }
145 }