]>
Commit | Line | Data |
---|---|---|
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, VideoPrivacy } from '@shared/models' | |
9 | import { getAllPrivacies } from '@shared/core-utils' | |
10 | ||
11 | @Injectable() | |
12 | export 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 [ | |
44 | { | |
45 | title: $localize`Video type`, | |
46 | children: [ | |
47 | { | |
48 | value: 'isLive:false', | |
49 | label: $localize`VOD` | |
50 | }, | |
51 | { | |
52 | value: 'isLive:true', | |
53 | label: $localize`Live` | |
54 | } | |
55 | ] | |
56 | }, | |
57 | ||
58 | { | |
59 | title: $localize`Video files`, | |
60 | children: [ | |
61 | { | |
62 | value: 'webtorrent:true isLocal:true', | |
63 | label: $localize`With WebTorrent` | |
64 | }, | |
65 | { | |
66 | value: 'webtorrent:false isLocal:true', | |
67 | label: $localize`Without WebTorrent` | |
68 | }, | |
69 | { | |
70 | value: 'hls:true isLocal:true', | |
71 | label: $localize`With HLS` | |
72 | }, | |
73 | { | |
74 | value: 'hls:false isLocal:true', | |
75 | label: $localize`Without HLS` | |
76 | } | |
77 | ] | |
78 | }, | |
79 | ||
80 | { | |
81 | title: $localize`Videos scope`, | |
82 | children: [ | |
83 | { | |
84 | value: 'isLocal:false', | |
85 | label: $localize`Remote videos` | |
86 | }, | |
87 | { | |
88 | value: 'isLocal:true', | |
89 | label: $localize`Local videos` | |
90 | } | |
91 | ] | |
92 | }, | |
93 | ||
94 | { | |
95 | title: $localize`Exclude`, | |
96 | children: [ | |
97 | { | |
98 | value: 'excludeMuted', | |
99 | label: $localize`Exclude muted accounts` | |
100 | }, | |
101 | { | |
102 | value: 'excludePublic', | |
103 | label: $localize`Exclude public videos` | |
104 | } | |
105 | ] | |
106 | } | |
107 | ] | |
108 | } | |
109 | ||
110 | private buildAdminParamsFromSearch (search: string, params: HttpParams) { | |
111 | let include = VideoInclude.BLACKLISTED | | |
112 | VideoInclude.BLOCKED_OWNER | | |
113 | VideoInclude.NOT_PUBLISHED_STATE | | |
114 | VideoInclude.FILES | |
115 | ||
116 | let privacyOneOf = getAllPrivacies() | |
117 | ||
118 | if (!search) return this.restService.addObjectParams(params, { include, privacyOneOf }) | |
119 | ||
120 | const filters = this.restService.parseQueryStringFilter(search, { | |
121 | isLocal: { | |
122 | prefix: 'isLocal:', | |
123 | isBoolean: true | |
124 | }, | |
125 | hasHLSFiles: { | |
126 | prefix: 'hls:', | |
127 | isBoolean: true | |
128 | }, | |
129 | hasWebtorrentFiles: { | |
130 | prefix: 'webtorrent:', | |
131 | isBoolean: true | |
132 | }, | |
133 | isLive: { | |
134 | prefix: 'isLive:', | |
135 | isBoolean: true | |
136 | }, | |
137 | excludeMuted: { | |
138 | prefix: 'excludeMuted', | |
139 | handler: () => true | |
140 | }, | |
141 | excludePublic: { | |
142 | prefix: 'excludePublic', | |
143 | handler: () => true | |
144 | } | |
145 | }) | |
146 | ||
147 | if (filters.excludeMuted) { | |
148 | include &= ~VideoInclude.BLOCKED_OWNER | |
149 | ||
150 | filters.excludeMuted = undefined | |
151 | } | |
152 | ||
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 }) | |
160 | } | |
161 | } |