]>
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 C |
42 | liveInfo: false, |
43 | removeFiles: true | |
33f6dce1 C |
44 | } |
45 | ||
231ff4af | 46 | loading = true |
61f85385 | 47 | |
33f6dce1 C |
48 | constructor ( |
49 | protected route: ActivatedRoute, | |
50 | protected router: Router, | |
51 | private confirmService: ConfirmService, | |
52 | private auth: AuthService, | |
53 | private notifier: Notifier, | |
05ac4ac7 | 54 | private videoService: VideoService, |
3cfa8176 C |
55 | private videoAdminService: VideoAdminService, |
56 | private videoBlockService: VideoBlockService | |
33f6dce1 C |
57 | ) { |
58 | super() | |
59 | } | |
60 | ||
61 | get authUser () { | |
62 | return this.auth.getUser() | |
63 | } | |
64 | ||
65 | ngOnInit () { | |
66 | this.initialize() | |
67 | ||
05ac4ac7 | 68 | this.inputFilters = this.videoAdminService.buildAdminInputFilter() |
231ff4af | 69 | |
33f6dce1 C |
70 | this.bulkVideoActions = [ |
71 | [ | |
72 | { | |
73 | label: $localize`Delete`, | |
74 | handler: videos => this.removeVideos(videos), | |
b46cf4b9 C |
75 | isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO), |
76 | iconName: 'delete' | |
3cfa8176 C |
77 | }, |
78 | { | |
79 | label: $localize`Block`, | |
80 | handler: videos => this.videoBlockModal.show(videos), | |
b46cf4b9 C |
81 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted), |
82 | iconName: 'no' | |
3cfa8176 C |
83 | }, |
84 | { | |
85 | label: $localize`Unblock`, | |
86 | handler: videos => this.unblockVideos(videos), | |
b46cf4b9 C |
87 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted), |
88 | iconName: 'undo' | |
89 | } | |
90 | ], | |
91 | [ | |
92 | { | |
93 | label: $localize`Delete HLS files`, | |
94 | handler: videos => this.removeVideoFiles(videos, 'hls'), | |
95 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_FILES) && videos.every(v => v.hasHLS() && v.hasWebTorrent()), | |
96 | iconName: 'delete' | |
97 | }, | |
98 | { | |
99 | label: $localize`Delete WebTorrent files`, | |
100 | handler: videos => this.removeVideoFiles(videos, 'webtorrent'), | |
101 | isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_FILES) && videos.every(v => v.hasHLS() && v.hasWebTorrent()), | |
102 | iconName: 'delete' | |
33f6dce1 C |
103 | } |
104 | ] | |
105 | ] | |
106 | } | |
107 | ||
108 | getIdentifier () { | |
109 | return 'VideoListComponent' | |
110 | } | |
111 | ||
112 | isInSelectionMode () { | |
113 | return this.selectedVideos.length !== 0 | |
114 | } | |
115 | ||
d324756e | 116 | getPrivacyBadgeClass (video: Video) { |
dd6d2a7c | 117 | if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green' |
2760b454 C |
118 | |
119 | return 'badge-yellow' | |
120 | } | |
121 | ||
d324756e C |
122 | isUnpublished (video: Video) { |
123 | return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED | |
2760b454 C |
124 | } |
125 | ||
126 | isAccountBlocked (video: Video) { | |
127 | return video.blockedOwner | |
128 | } | |
129 | ||
130 | isServerBlocked (video: Video) { | |
131 | return video.blockedServer | |
132 | } | |
133 | ||
134 | isVideoBlocked (video: Video) { | |
135 | return video.blacklisted | |
136 | } | |
137 | ||
d324756e C |
138 | isImport (video: Video) { |
139 | return video.state.id === VideoState.TO_IMPORT | |
140 | } | |
141 | ||
3c10840f | 142 | isHLS (video: Video) { |
d5d9c5b7 C |
143 | const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) |
144 | if (!p) return false | |
145 | ||
146 | return p.files.length !== 0 | |
3c10840f C |
147 | } |
148 | ||
149 | isWebTorrent (video: Video) { | |
150 | return video.files.length !== 0 | |
151 | } | |
152 | ||
153 | getFilesSize (video: Video) { | |
154 | let files = video.files | |
155 | ||
156 | if (this.isHLS(video)) { | |
157 | files = files.concat(video.streamingPlaylists[0].files) | |
158 | } | |
159 | ||
160 | return files.reduce((p, f) => p += f.size, 0) | |
161 | } | |
162 | ||
b46cf4b9 | 163 | reloadData () { |
33f6dce1 C |
164 | this.selectedVideos = [] |
165 | ||
61f85385 C |
166 | this.loading = true |
167 | ||
05ac4ac7 | 168 | this.videoAdminService.getAdminVideos({ |
33f6dce1 C |
169 | pagination: this.pagination, |
170 | sort: this.sort, | |
171 | search: this.search | |
61f85385 C |
172 | }).pipe(finalize(() => this.loading = false)) |
173 | .subscribe({ | |
174 | next: resultList => { | |
175 | this.videos = resultList.data | |
176 | this.totalRecords = resultList.total | |
177 | }, | |
178 | ||
179 | error: err => this.notifier.error(err.message) | |
180 | }) | |
33f6dce1 C |
181 | } |
182 | ||
183 | private async removeVideos (videos: Video[]) { | |
184 | const message = $localize`Are you sure you want to delete these ${videos.length} videos?` | |
185 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
186 | if (res === false) return | |
187 | ||
188 | this.videoService.removeVideo(videos.map(v => v.id)) | |
189 | .subscribe({ | |
190 | next: () => { | |
3cfa8176 C |
191 | this.notifier.success($localize`Deleted ${videos.length} videos.`) |
192 | this.reloadData() | |
193 | }, | |
194 | ||
195 | error: err => this.notifier.error(err.message) | |
196 | }) | |
197 | } | |
198 | ||
199 | private unblockVideos (videos: Video[]) { | |
200 | this.videoBlockService.unblockVideo(videos.map(v => v.id)) | |
201 | .subscribe({ | |
202 | next: () => { | |
203 | this.notifier.success($localize`Unblocked ${videos.length} videos.`) | |
33f6dce1 C |
204 | this.reloadData() |
205 | }, | |
206 | ||
207 | error: err => this.notifier.error(err.message) | |
208 | }) | |
209 | } | |
b46cf4b9 C |
210 | |
211 | private async removeVideoFiles (videos: Video[], type: 'hls' | 'webtorrent') { | |
212 | const message = type === 'hls' | |
213 | ? $localize`Are you sure you want to delete ${videos.length} HLS streaming playlists?` | |
214 | : $localize`Are you sure you want to delete WebTorrent files of ${videos.length} videos?` | |
215 | ||
216 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
217 | if (res === false) return | |
218 | ||
219 | this.videoService.removeVideoFiles(videos.map(v => v.id), type) | |
220 | .subscribe({ | |
221 | next: () => { | |
222 | this.notifier.success($localize`Files were removed.`) | |
223 | this.reloadData() | |
224 | }, | |
225 | ||
226 | error: err => this.notifier.error(err.message) | |
227 | }) | |
228 | } | |
33f6dce1 | 229 | } |