]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/overview/videos/video-admin.service.ts
Add ability to filter live videos
[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 queryParams: { search: 'isLive:false' },
48 label: $localize`VOD videos`
49 },
50 {
51 queryParams: { search: 'isLive:true' },
52 label: $localize`Live videos`
53 }
54 ]
55 },
56
57 {
58 title: $localize`Videos scope`,
59 children: [
60 {
61 queryParams: { search: 'isLocal:false' },
62 label: $localize`Remote videos`
63 },
64 {
65 queryParams: { search: 'isLocal:true' },
66 label: $localize`Local videos`
67 }
68 ]
69 },
70
71 {
72 title: $localize`Include/Exclude`,
73 children: [
74 {
75 queryParams: { search: 'excludeMuted' },
76 label: $localize`Exclude muted accounts`
77 }
78 ]
79 }
80 ]
81 }
82
83 private buildAdminParamsFromSearch (search: string, params: HttpParams) {
84 let include = VideoInclude.BLACKLISTED |
85 VideoInclude.BLOCKED_OWNER |
86 VideoInclude.HIDDEN_PRIVACY |
87 VideoInclude.NOT_PUBLISHED_STATE |
88 VideoInclude.FILES
89
90 if (!search) return this.restService.addObjectParams(params, { include })
91
92 const filters = this.restService.parseQueryStringFilter(search, {
93 isLocal: {
94 prefix: 'isLocal:',
95 isBoolean: true
96 },
97 isLive: {
98 prefix: 'isLive:',
99 isBoolean: true
100 },
101 excludeMuted: {
102 prefix: 'excludeMuted',
103 handler: () => true
104 }
105 })
106
107 if (filters.excludeMuted) {
108 include &= ~VideoInclude.BLOCKED_OWNER
109
110 filters.excludeMuted = undefined
111 }
112
113 return this.restService.addObjectParams(params, { ...filters, include })
114 }
115 }