]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/videos/video-admin.service.ts
Add ability to filter by file type
[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'
8import { ResultList, VideoInclude } from '@shared/models'
9
10@Injectable()
11export 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 [
d5d9c5b7
C
43 {
44 title: $localize`Video type`,
45 children: [
46 {
47 queryParams: { search: 'isLive:false' },
d324756e 48 label: $localize`VOD`
d5d9c5b7
C
49 },
50 {
51 queryParams: { search: 'isLive:true' },
d324756e
C
52 label: $localize`Live`
53 }
54 ]
55 },
56
57 {
58 title: $localize`Video files`,
59 children: [
60 {
61 queryParams: { search: 'webtorrent:true' },
62 label: $localize`With WebTorrent`
63 },
64 {
65 queryParams: { search: 'webtorrent:false' },
66 label: $localize`Without WebTorrent`
67 },
68 {
69 queryParams: { search: 'hls:true' },
70 label: $localize`With HLS`
71 },
72 {
73 queryParams: { search: 'hls:false' },
74 label: $localize`Without HLS`
d5d9c5b7
C
75 }
76 ]
77 },
78
05ac4ac7
C
79 {
80 title: $localize`Videos scope`,
81 children: [
82 {
83 queryParams: { search: 'isLocal:false' },
84 label: $localize`Remote videos`
85 },
86 {
87 queryParams: { search: 'isLocal:true' },
88 label: $localize`Local videos`
89 }
90 ]
91 },
92
93 {
d324756e 94 title: $localize`Exclude`,
05ac4ac7
C
95 children: [
96 {
97 queryParams: { search: '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 },
d324756e
C
119 hasHLSFiles: {
120 prefix: 'hls:',
121 isBoolean: true
122 },
123 hasWebtorrentFiles: {
124 prefix: 'webtorrent:',
125 isBoolean: true
126 },
d5d9c5b7
C
127 isLive: {
128 prefix: 'isLive:',
129 isBoolean: true
130 },
05ac4ac7
C
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}