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