]>
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' |
1bb4c9ab | 11 | import { UserRight, VideoFile, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' |
05ac4ac7 | 12 | import { VideoAdminService } from './video-admin.service' |
33f6dce1 C |
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 { | |
3cfa8176 C |
20 | @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent |
21 | ||
33f6dce1 C |
22 | videos: Video[] = [] |
23 | ||
24 | totalRecords = 0 | |
7e7d8e48 | 25 | sort: SortMeta = { field: 'publishedAt', order: -1 } |
33f6dce1 C |
26 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
27 | ||
28 | bulkVideoActions: DropdownAction<Video[]>[][] = [] | |
29 | ||
30 | selectedVideos: Video[] = [] | |
31 | ||
231ff4af | 32 | inputFilters: AdvancedInputFilter[] |
33f6dce1 C |
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, | |
b46cf4b9 | 43 | liveInfo: false, |
ad5db104 | 44 | removeFiles: true, |
384ba8b7 C |
45 | transcoding: true, |
46 | studio: true, | |
47 | stats: true | |
33f6dce1 C |
48 | } |
49 | ||
231ff4af | 50 | loading = true |
61f85385 | 51 | |
33f6dce1 C |
52 | constructor ( |
53 | protected route: ActivatedRoute, | |
54 | protected router: Router, | |
55 | private confirmService: ConfirmService, | |
56 | private auth: AuthService, | |
57 | private notifier: Notifier, | |
05ac4ac7 | 58 | private videoService: VideoService, |
3cfa8176 C |
59 | private videoAdminService: VideoAdminService, |
60 | private videoBlockService: VideoBlockService | |
33f6dce1 C |
61 | ) { |
62 | super() | |
63 | } | |
64 | ||
65 | get authUser () { | |
66 | return this.auth.getUser() | |
67 | } | |
68 | ||
69 | ngOnInit () { | |
70 | this.initialize() | |
71 | ||
05ac4ac7 | 72 | this.inputFilters = this.videoAdminService.buildAdminInputFilter() |
231ff4af | 73 | |
33f6dce1 C |
74 | this.bulkVideoActions = [ |
75 | [ | |
76 | { | |
77 | label: $localize`Delete`, | |
78 | handler: videos => this.removeVideos(videos), | |
b46cf4b9 C |
79 | isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO), |
80 | iconName: 'delete' | |
3cfa8176 C |
81 | }, |
82 | { | |
83 | label: $localize`Block`, | |
84 | handler: videos => this.videoBlockModal.show(videos), | |
b46cf4b9 C |
85 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted), |
86 | iconName: 'no' | |
3cfa8176 C |
87 | }, |
88 | { | |
89 | label: $localize`Unblock`, | |
90 | handler: videos => this.unblockVideos(videos), | |
b46cf4b9 C |
91 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted), |
92 | iconName: 'undo' | |
93 | } | |
94 | ], | |
95 | [ | |
ad5db104 C |
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 | }, | |
b46cf4b9 C |
108 | { |
109 | label: $localize`Delete HLS files`, | |
110 | handler: videos => this.removeVideoFiles(videos, 'hls'), | |
ad5db104 | 111 | isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)), |
b46cf4b9 C |
112 | iconName: 'delete' |
113 | }, | |
114 | { | |
115 | label: $localize`Delete WebTorrent files`, | |
116 | handler: videos => this.removeVideoFiles(videos, 'webtorrent'), | |
ad5db104 | 117 | isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)), |
b46cf4b9 | 118 | iconName: 'delete' |
33f6dce1 C |
119 | } |
120 | ] | |
121 | ] | |
122 | } | |
123 | ||
124 | getIdentifier () { | |
125 | return 'VideoListComponent' | |
126 | } | |
127 | ||
128 | isInSelectionMode () { | |
129 | return this.selectedVideos.length !== 0 | |
130 | } | |
131 | ||
d324756e | 132 | getPrivacyBadgeClass (video: Video) { |
dd6d2a7c | 133 | if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green' |
2760b454 C |
134 | |
135 | return 'badge-yellow' | |
136 | } | |
137 | ||
d324756e C |
138 | isUnpublished (video: Video) { |
139 | return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED | |
2760b454 C |
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 | ||
d324756e C |
154 | isImport (video: Video) { |
155 | return video.state.id === VideoState.TO_IMPORT | |
156 | } | |
157 | ||
3c10840f | 158 | isHLS (video: Video) { |
d5d9c5b7 C |
159 | const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) |
160 | if (!p) return false | |
161 | ||
162 | return p.files.length !== 0 | |
3c10840f C |
163 | } |
164 | ||
165 | isWebTorrent (video: Video) { | |
166 | return video.files.length !== 0 | |
167 | } | |
168 | ||
169 | getFilesSize (video: Video) { | |
170 | let files = video.files | |
171 | ||
172 | if (this.isHLS(video)) { | |
173 | files = files.concat(video.streamingPlaylists[0].files) | |
174 | } | |
175 | ||
176 | return files.reduce((p, f) => p += f.size, 0) | |
177 | } | |
178 | ||
b46cf4b9 | 179 | reloadData () { |
33f6dce1 C |
180 | this.selectedVideos = [] |
181 | ||
61f85385 C |
182 | this.loading = true |
183 | ||
05ac4ac7 | 184 | this.videoAdminService.getAdminVideos({ |
33f6dce1 C |
185 | pagination: this.pagination, |
186 | sort: this.sort, | |
187 | search: this.search | |
61f85385 C |
188 | }).pipe(finalize(() => this.loading = false)) |
189 | .subscribe({ | |
190 | next: resultList => { | |
191 | this.videos = resultList.data | |
192 | this.totalRecords = resultList.total | |
193 | }, | |
194 | ||
195 | error: err => this.notifier.error(err.message) | |
196 | }) | |
33f6dce1 C |
197 | } |
198 | ||
1bb4c9ab C |
199 | async removeVideoFile (video: Video, file: VideoFile, type: 'hls' | 'webtorrent') { |
200 | const message = $localize`Are you sure you want to delete this ${file.resolution.label} file?` | |
201 | const res = await this.confirmService.confirm(message, $localize`Delete file`) | |
202 | if (res === false) return | |
203 | ||
204 | this.videoService.removeFile(video.uuid, file.id, type) | |
205 | .subscribe({ | |
206 | next: () => { | |
207 | this.notifier.success($localize`File removed.`) | |
208 | this.reloadData() | |
209 | }, | |
210 | ||
211 | error: err => this.notifier.error(err.message) | |
212 | }) | |
213 | } | |
214 | ||
33f6dce1 | 215 | private async removeVideos (videos: Video[]) { |
eaa52952 C |
216 | const message = prepareIcu($localize`Are you sure you want to delete {count, plural, =1 {this video} other {these {count} videos}}?`)( |
217 | { count: videos.length }, | |
218 | $localize`Are you sure you want to delete these ${videos.length} videos?` | |
219 | ) | |
220 | ||
33f6dce1 C |
221 | const res = await this.confirmService.confirm(message, $localize`Delete`) |
222 | if (res === false) return | |
223 | ||
224 | this.videoService.removeVideo(videos.map(v => v.id)) | |
225 | .subscribe({ | |
226 | next: () => { | |
eaa52952 C |
227 | this.notifier.success( |
228 | prepareIcu($localize`Deleted {count, plural, =1 {1 video} other {{count} videos}}.`)( | |
229 | { count: videos.length }, | |
230 | $localize`Deleted ${videos.length} videos.` | |
231 | ) | |
232 | ) | |
233 | ||
3cfa8176 C |
234 | this.reloadData() |
235 | }, | |
236 | ||
237 | error: err => this.notifier.error(err.message) | |
238 | }) | |
239 | } | |
240 | ||
241 | private unblockVideos (videos: Video[]) { | |
242 | this.videoBlockService.unblockVideo(videos.map(v => v.id)) | |
243 | .subscribe({ | |
244 | next: () => { | |
eaa52952 C |
245 | this.notifier.success( |
246 | prepareIcu($localize`Unblocked {count, plural, =1 {1 video} other {{count} videos}}.`)( | |
247 | { count: videos.length }, | |
248 | $localize`Unblocked ${videos.length} videos.` | |
249 | ) | |
250 | ) | |
251 | ||
33f6dce1 C |
252 | this.reloadData() |
253 | }, | |
254 | ||
255 | error: err => this.notifier.error(err.message) | |
256 | }) | |
257 | } | |
b46cf4b9 C |
258 | |
259 | private async removeVideoFiles (videos: Video[], type: 'hls' | 'webtorrent') { | |
eaa52952 C |
260 | let message: string |
261 | ||
262 | if (type === 'hls') { | |
263 | // eslint-disable-next-line max-len | |
264 | message = prepareIcu($localize`Are you sure you want to delete {count, plural, =1 {1 HLS streaming playlist} other {{count} HLS streaming playlists}}?`)( | |
265 | { count: videos.length }, | |
266 | $localize`Are you sure you want to delete ${videos.length} HLS streaming playlists?` | |
267 | ) | |
268 | } else { | |
269 | // eslint-disable-next-line max-len | |
270 | message = prepareIcu($localize`Are you sure you want to delete WebTorrent files of {count, plural, =1 {1 video} other {{count} videos}}?`)( | |
271 | { count: videos.length }, | |
272 | $localize`Are you sure you want to delete WebTorrent files of ${videos.length} videos?` | |
273 | ) | |
274 | } | |
b46cf4b9 C |
275 | |
276 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
277 | if (res === false) return | |
278 | ||
279 | this.videoService.removeVideoFiles(videos.map(v => v.id), type) | |
280 | .subscribe({ | |
281 | next: () => { | |
282 | this.notifier.success($localize`Files were removed.`) | |
283 | this.reloadData() | |
284 | }, | |
285 | ||
286 | error: err => this.notifier.error(err.message) | |
287 | }) | |
288 | } | |
ad5db104 C |
289 | |
290 | private runTranscoding (videos: Video[], type: 'hls' | 'webtorrent') { | |
291 | this.videoService.runTranscoding(videos.map(v => v.id), type) | |
292 | .subscribe({ | |
293 | next: () => { | |
294 | this.notifier.success($localize`Transcoding jobs created.`) | |
295 | ||
296 | this.reloadData() | |
297 | }, | |
298 | ||
299 | error: err => this.notifier.error(err.message) | |
300 | }) | |
301 | } | |
33f6dce1 | 302 | } |