]>
Commit | Line | Data |
---|---|---|
05ac4ac7 C |
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 [ | |
d5d9c5b7 C |
43 | { |
44 | title: $localize`Video type`, | |
45 | children: [ | |
46 | { | |
dd6d2a7c | 47 | value: 'isLive:false', |
d324756e | 48 | label: $localize`VOD` |
d5d9c5b7 C |
49 | }, |
50 | { | |
dd6d2a7c | 51 | value: 'isLive:true', |
d324756e C |
52 | label: $localize`Live` |
53 | } | |
54 | ] | |
55 | }, | |
56 | ||
57 | { | |
58 | title: $localize`Video files`, | |
59 | children: [ | |
60 | { | |
dd6d2a7c | 61 | value: 'webtorrent:true', |
d324756e C |
62 | label: $localize`With WebTorrent` |
63 | }, | |
64 | { | |
dd6d2a7c | 65 | value: 'webtorrent:false', |
d324756e C |
66 | label: $localize`Without WebTorrent` |
67 | }, | |
68 | { | |
dd6d2a7c | 69 | value: 'hls:true', |
d324756e C |
70 | label: $localize`With HLS` |
71 | }, | |
72 | { | |
dd6d2a7c | 73 | value: 'hls:false', |
d324756e | 74 | label: $localize`Without HLS` |
d5d9c5b7 C |
75 | } |
76 | ] | |
77 | }, | |
78 | ||
05ac4ac7 C |
79 | { |
80 | title: $localize`Videos scope`, | |
81 | children: [ | |
82 | { | |
dd6d2a7c | 83 | value: 'isLocal:false', |
05ac4ac7 C |
84 | label: $localize`Remote videos` |
85 | }, | |
86 | { | |
dd6d2a7c | 87 | value: 'isLocal:true', |
05ac4ac7 C |
88 | label: $localize`Local videos` |
89 | } | |
90 | ] | |
91 | }, | |
92 | ||
93 | { | |
d324756e | 94 | title: $localize`Exclude`, |
05ac4ac7 C |
95 | children: [ |
96 | { | |
dd6d2a7c | 97 | value: 'excludeMuted', |
05ac4ac7 C |
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 | } |