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