]>
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' | |
33f6dce1 | 6 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
61f85385 | 7 | import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' |
3cfa8176 | 8 | import { VideoBlockComponent, VideoBlockService } from '@app/shared/shared-moderation' |
33f6dce1 | 9 | import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature' |
61f85385 | 10 | import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' |
05ac4ac7 | 11 | import { VideoAdminService } from './video-admin.service' |
33f6dce1 C |
12 | |
13 | @Component({ | |
14 | selector: 'my-video-list', | |
15 | templateUrl: './video-list.component.html', | |
16 | styleUrls: [ './video-list.component.scss' ] | |
17 | }) | |
18 | export class VideoListComponent extends RestTable implements OnInit { | |
3cfa8176 C |
19 | @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent |
20 | ||
33f6dce1 C |
21 | videos: Video[] = [] |
22 | ||
23 | totalRecords = 0 | |
7e7d8e48 | 24 | sort: SortMeta = { field: 'publishedAt', order: -1 } |
33f6dce1 C |
25 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
26 | ||
27 | bulkVideoActions: DropdownAction<Video[]>[][] = [] | |
28 | ||
29 | selectedVideos: Video[] = [] | |
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 | |
33f6dce1 C |
73 | this.bulkVideoActions = [ |
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 | ||
127 | isInSelectionMode () { | |
128 | return this.selectedVideos.length !== 0 | |
129 | } | |
130 | ||
d324756e | 131 | getPrivacyBadgeClass (video: Video) { |
dd6d2a7c | 132 | if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green' |
2760b454 C |
133 | |
134 | return 'badge-yellow' | |
135 | } | |
136 | ||
d324756e C |
137 | isUnpublished (video: Video) { |
138 | return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED | |
2760b454 C |
139 | } |
140 | ||
141 | isAccountBlocked (video: Video) { | |
142 | return video.blockedOwner | |
143 | } | |
144 | ||
145 | isServerBlocked (video: Video) { | |
146 | return video.blockedServer | |
147 | } | |
148 | ||
149 | isVideoBlocked (video: Video) { | |
150 | return video.blacklisted | |
151 | } | |
152 | ||
d324756e C |
153 | isImport (video: Video) { |
154 | return video.state.id === VideoState.TO_IMPORT | |
155 | } | |
156 | ||
3c10840f | 157 | isHLS (video: Video) { |
d5d9c5b7 C |
158 | const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) |
159 | if (!p) return false | |
160 | ||
161 | return p.files.length !== 0 | |
3c10840f C |
162 | } |
163 | ||
164 | isWebTorrent (video: Video) { | |
165 | return video.files.length !== 0 | |
166 | } | |
167 | ||
168 | getFilesSize (video: Video) { | |
169 | let files = video.files | |
170 | ||
171 | if (this.isHLS(video)) { | |
172 | files = files.concat(video.streamingPlaylists[0].files) | |
173 | } | |
174 | ||
175 | return files.reduce((p, f) => p += f.size, 0) | |
176 | } | |
177 | ||
b46cf4b9 | 178 | reloadData () { |
33f6dce1 C |
179 | this.selectedVideos = [] |
180 | ||
61f85385 C |
181 | this.loading = true |
182 | ||
05ac4ac7 | 183 | this.videoAdminService.getAdminVideos({ |
33f6dce1 C |
184 | pagination: this.pagination, |
185 | sort: this.sort, | |
186 | search: this.search | |
61f85385 C |
187 | }).pipe(finalize(() => this.loading = false)) |
188 | .subscribe({ | |
189 | next: resultList => { | |
190 | this.videos = resultList.data | |
191 | this.totalRecords = resultList.total | |
192 | }, | |
193 | ||
194 | error: err => this.notifier.error(err.message) | |
195 | }) | |
33f6dce1 C |
196 | } |
197 | ||
198 | private async removeVideos (videos: Video[]) { | |
199 | const message = $localize`Are you sure you want to delete these ${videos.length} videos?` | |
200 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
201 | if (res === false) return | |
202 | ||
203 | this.videoService.removeVideo(videos.map(v => v.id)) | |
204 | .subscribe({ | |
205 | next: () => { | |
3cfa8176 C |
206 | this.notifier.success($localize`Deleted ${videos.length} videos.`) |
207 | this.reloadData() | |
208 | }, | |
209 | ||
210 | error: err => this.notifier.error(err.message) | |
211 | }) | |
212 | } | |
213 | ||
214 | private unblockVideos (videos: Video[]) { | |
215 | this.videoBlockService.unblockVideo(videos.map(v => v.id)) | |
216 | .subscribe({ | |
217 | next: () => { | |
218 | this.notifier.success($localize`Unblocked ${videos.length} videos.`) | |
33f6dce1 C |
219 | this.reloadData() |
220 | }, | |
221 | ||
222 | error: err => this.notifier.error(err.message) | |
223 | }) | |
224 | } | |
b46cf4b9 C |
225 | |
226 | private async removeVideoFiles (videos: Video[], type: 'hls' | 'webtorrent') { | |
227 | const message = type === 'hls' | |
228 | ? $localize`Are you sure you want to delete ${videos.length} HLS streaming playlists?` | |
229 | : $localize`Are you sure you want to delete WebTorrent files of ${videos.length} videos?` | |
230 | ||
231 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
232 | if (res === false) return | |
233 | ||
234 | this.videoService.removeVideoFiles(videos.map(v => v.id), type) | |
235 | .subscribe({ | |
236 | next: () => { | |
237 | this.notifier.success($localize`Files were removed.`) | |
238 | this.reloadData() | |
239 | }, | |
240 | ||
241 | error: err => this.notifier.error(err.message) | |
242 | }) | |
243 | } | |
ad5db104 C |
244 | |
245 | private runTranscoding (videos: Video[], type: 'hls' | 'webtorrent') { | |
246 | this.videoService.runTranscoding(videos.map(v => v.id), type) | |
247 | .subscribe({ | |
248 | next: () => { | |
249 | this.notifier.success($localize`Transcoding jobs created.`) | |
250 | ||
251 | this.reloadData() | |
252 | }, | |
253 | ||
254 | error: err => this.notifier.error(err.message) | |
255 | }) | |
256 | } | |
33f6dce1 | 257 | } |