]>
Commit | Line | Data |
---|---|---|
1 | import { SortMeta } from 'primeng/api' | |
2 | import { finalize } from 'rxjs/operators' | |
3 | import { Component, OnInit, ViewChild } from '@angular/core' | |
4 | import { ActivatedRoute, Router } from '@angular/router' | |
5 | import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | |
6 | import { prepareIcu } from '@app/helpers' | |
7 | import { AdvancedInputFilter } from '@app/shared/shared-forms' | |
8 | import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' | |
9 | import { VideoBlockComponent, VideoBlockService } from '@app/shared/shared-moderation' | |
10 | import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature' | |
11 | import { UserRight, VideoFile, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' | |
12 | import { VideoAdminService } from './video-admin.service' | |
13 | ||
14 | @Component({ | |
15 | selector: 'my-video-list', | |
16 | templateUrl: './video-list.component.html', | |
17 | styleUrls: [ './video-list.component.scss' ] | |
18 | }) | |
19 | export class VideoListComponent extends RestTable implements OnInit { | |
20 | @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent | |
21 | ||
22 | videos: Video[] = [] | |
23 | ||
24 | totalRecords = 0 | |
25 | sort: SortMeta = { field: 'publishedAt', order: -1 } | |
26 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
27 | ||
28 | bulkVideoActions: DropdownAction<Video[]>[][] = [] | |
29 | ||
30 | selectedVideos: Video[] = [] | |
31 | ||
32 | inputFilters: AdvancedInputFilter[] | |
33 | ||
34 | videoActionsOptions: VideoActionsDisplayType = { | |
35 | playlist: false, | |
36 | download: false, | |
37 | update: true, | |
38 | blacklist: true, | |
39 | delete: true, | |
40 | report: false, | |
41 | duplicate: true, | |
42 | mute: true, | |
43 | liveInfo: false, | |
44 | removeFiles: true, | |
45 | transcoding: true, | |
46 | studio: true, | |
47 | stats: true | |
48 | } | |
49 | ||
50 | loading = true | |
51 | ||
52 | constructor ( | |
53 | protected route: ActivatedRoute, | |
54 | protected router: Router, | |
55 | private confirmService: ConfirmService, | |
56 | private auth: AuthService, | |
57 | private notifier: Notifier, | |
58 | private videoService: VideoService, | |
59 | private videoAdminService: VideoAdminService, | |
60 | private videoBlockService: VideoBlockService | |
61 | ) { | |
62 | super() | |
63 | } | |
64 | ||
65 | get authUser () { | |
66 | return this.auth.getUser() | |
67 | } | |
68 | ||
69 | ngOnInit () { | |
70 | this.initialize() | |
71 | ||
72 | this.inputFilters = this.videoAdminService.buildAdminInputFilter() | |
73 | ||
74 | this.bulkVideoActions = [ | |
75 | [ | |
76 | { | |
77 | label: $localize`Delete`, | |
78 | handler: videos => this.removeVideos(videos), | |
79 | isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO), | |
80 | iconName: 'delete' | |
81 | }, | |
82 | { | |
83 | label: $localize`Block`, | |
84 | handler: videos => this.videoBlockModal.show(videos), | |
85 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted), | |
86 | iconName: 'no' | |
87 | }, | |
88 | { | |
89 | label: $localize`Unblock`, | |
90 | handler: videos => this.unblockVideos(videos), | |
91 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted), | |
92 | iconName: 'undo' | |
93 | } | |
94 | ], | |
95 | [ | |
96 | { | |
97 | label: $localize`Run HLS transcoding`, | |
98 | handler: videos => this.runTranscoding(videos, 'hls'), | |
99 | isDisplayed: videos => videos.every(v => v.canRunTranscoding(this.authUser)), | |
100 | iconName: 'cog' | |
101 | }, | |
102 | { | |
103 | label: $localize`Run WebTorrent transcoding`, | |
104 | handler: videos => this.runTranscoding(videos, 'webtorrent'), | |
105 | isDisplayed: videos => videos.every(v => v.canRunTranscoding(this.authUser)), | |
106 | iconName: 'cog' | |
107 | }, | |
108 | { | |
109 | label: $localize`Delete HLS files`, | |
110 | handler: videos => this.removeVideoFiles(videos, 'hls'), | |
111 | isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)), | |
112 | iconName: 'delete' | |
113 | }, | |
114 | { | |
115 | label: $localize`Delete WebTorrent files`, | |
116 | handler: videos => this.removeVideoFiles(videos, 'webtorrent'), | |
117 | isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)), | |
118 | iconName: 'delete' | |
119 | } | |
120 | ] | |
121 | ] | |
122 | } | |
123 | ||
124 | getIdentifier () { | |
125 | return 'VideoListComponent' | |
126 | } | |
127 | ||
128 | isInSelectionMode () { | |
129 | return this.selectedVideos.length !== 0 | |
130 | } | |
131 | ||
132 | getPrivacyBadgeClass (video: Video) { | |
133 | if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green' | |
134 | ||
135 | return 'badge-yellow' | |
136 | } | |
137 | ||
138 | isUnpublished (video: Video) { | |
139 | return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED | |
140 | } | |
141 | ||
142 | isAccountBlocked (video: Video) { | |
143 | return video.blockedOwner | |
144 | } | |
145 | ||
146 | isServerBlocked (video: Video) { | |
147 | return video.blockedServer | |
148 | } | |
149 | ||
150 | isVideoBlocked (video: Video) { | |
151 | return video.blacklisted | |
152 | } | |
153 | ||
154 | isImport (video: Video) { | |
155 | return video.state.id === VideoState.TO_IMPORT | |
156 | } | |
157 | ||
158 | isHLS (video: Video) { | |
159 | const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | |
160 | if (!p) return false | |
161 | ||
162 | return p.files.length !== 0 | |
163 | } | |
164 | ||
165 | isWebTorrent (video: Video) { | |
166 | return video.files.length !== 0 | |
167 | } | |
168 | ||
169 | canRemoveOneFile (video: Video) { | |
170 | return video.canRemoveOneFile(this.authUser) | |
171 | } | |
172 | ||
173 | getFilesSize (video: Video) { | |
174 | let files = video.files | |
175 | ||
176 | if (this.isHLS(video)) { | |
177 | files = files.concat(video.streamingPlaylists[0].files) | |
178 | } | |
179 | ||
180 | return files.reduce((p, f) => p += f.size, 0) | |
181 | } | |
182 | ||
183 | reloadData () { | |
184 | this.selectedVideos = [] | |
185 | ||
186 | this.loading = true | |
187 | ||
188 | this.videoAdminService.getAdminVideos({ | |
189 | pagination: this.pagination, | |
190 | sort: this.sort, | |
191 | search: this.search | |
192 | }).pipe(finalize(() => this.loading = false)) | |
193 | .subscribe({ | |
194 | next: resultList => { | |
195 | this.videos = resultList.data | |
196 | this.totalRecords = resultList.total | |
197 | }, | |
198 | ||
199 | error: err => this.notifier.error(err.message) | |
200 | }) | |
201 | } | |
202 | ||
203 | async removeVideoFile (video: Video, file: VideoFile, type: 'hls' | 'webtorrent') { | |
204 | const message = $localize`Are you sure you want to delete this ${file.resolution.label} file?` | |
205 | const res = await this.confirmService.confirm(message, $localize`Delete file`) | |
206 | if (res === false) return | |
207 | ||
208 | this.videoService.removeFile(video.uuid, file.id, type) | |
209 | .subscribe({ | |
210 | next: () => { | |
211 | this.notifier.success($localize`File removed.`) | |
212 | this.reloadData() | |
213 | }, | |
214 | ||
215 | error: err => this.notifier.error(err.message) | |
216 | }) | |
217 | } | |
218 | ||
219 | private async removeVideos (videos: Video[]) { | |
220 | const message = prepareIcu($localize`Are you sure you want to delete {count, plural, =1 {this video} other {these {count} videos}}?`)( | |
221 | { count: videos.length }, | |
222 | $localize`Are you sure you want to delete these ${videos.length} videos?` | |
223 | ) | |
224 | ||
225 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
226 | if (res === false) return | |
227 | ||
228 | this.videoService.removeVideo(videos.map(v => v.id)) | |
229 | .subscribe({ | |
230 | next: () => { | |
231 | this.notifier.success( | |
232 | prepareIcu($localize`Deleted {count, plural, =1 {1 video} other {{count} videos}}.`)( | |
233 | { count: videos.length }, | |
234 | $localize`Deleted ${videos.length} videos.` | |
235 | ) | |
236 | ) | |
237 | ||
238 | this.reloadData() | |
239 | }, | |
240 | ||
241 | error: err => this.notifier.error(err.message) | |
242 | }) | |
243 | } | |
244 | ||
245 | private unblockVideos (videos: Video[]) { | |
246 | this.videoBlockService.unblockVideo(videos.map(v => v.id)) | |
247 | .subscribe({ | |
248 | next: () => { | |
249 | this.notifier.success( | |
250 | prepareIcu($localize`Unblocked {count, plural, =1 {1 video} other {{count} videos}}.`)( | |
251 | { count: videos.length }, | |
252 | $localize`Unblocked ${videos.length} videos.` | |
253 | ) | |
254 | ) | |
255 | ||
256 | this.reloadData() | |
257 | }, | |
258 | ||
259 | error: err => this.notifier.error(err.message) | |
260 | }) | |
261 | } | |
262 | ||
263 | private async removeVideoFiles (videos: Video[], type: 'hls' | 'webtorrent') { | |
264 | let message: string | |
265 | ||
266 | if (type === 'hls') { | |
267 | // eslint-disable-next-line max-len | |
268 | message = prepareIcu($localize`Are you sure you want to delete {count, plural, =1 {1 HLS streaming playlist} other {{count} HLS streaming playlists}}?`)( | |
269 | { count: videos.length }, | |
270 | $localize`Are you sure you want to delete ${videos.length} HLS streaming playlists?` | |
271 | ) | |
272 | } else { | |
273 | // eslint-disable-next-line max-len | |
274 | message = prepareIcu($localize`Are you sure you want to delete WebTorrent files of {count, plural, =1 {1 video} other {{count} videos}}?`)( | |
275 | { count: videos.length }, | |
276 | $localize`Are you sure you want to delete WebTorrent files of ${videos.length} videos?` | |
277 | ) | |
278 | } | |
279 | ||
280 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
281 | if (res === false) return | |
282 | ||
283 | this.videoService.removeVideoFiles(videos.map(v => v.id), type) | |
284 | .subscribe({ | |
285 | next: () => { | |
286 | this.notifier.success($localize`Files were removed.`) | |
287 | this.reloadData() | |
288 | }, | |
289 | ||
290 | error: err => this.notifier.error(err.message) | |
291 | }) | |
292 | } | |
293 | ||
294 | private runTranscoding (videos: Video[], type: 'hls' | 'webtorrent') { | |
295 | this.videoService.runTranscoding(videos.map(v => v.id), type) | |
296 | .subscribe({ | |
297 | next: () => { | |
298 | this.notifier.success($localize`Transcoding jobs created.`) | |
299 | ||
300 | this.reloadData() | |
301 | }, | |
302 | ||
303 | error: err => this.notifier.error(err.message) | |
304 | }) | |
305 | } | |
306 | } |