1 import { SortMeta } from 'primeng/api'
2 import { finalize } from 'rxjs/operators'
3 import { Component, OnInit, ViewChild } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
5 import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
6 import { AdvancedInputFilter } from '@app/shared/shared-forms'
7 import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
8 import { VideoBlockComponent, VideoBlockService } from '@app/shared/shared-moderation'
9 import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
10 import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
11 import { VideoAdminService } from './video-admin.service'
14 selector: 'my-video-list',
15 templateUrl: './video-list.component.html',
16 styleUrls: [ './video-list.component.scss' ]
18 export class VideoListComponent extends RestTable implements OnInit {
19 @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
24 sort: SortMeta = { field: 'publishedAt', order: -1 }
25 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
27 bulkVideoActions: DropdownAction<Video[]>[][] = []
29 selectedVideos: Video[] = []
31 inputFilters: AdvancedInputFilter[]
33 videoActionsOptions: VideoActionsDisplayType = {
52 protected route: ActivatedRoute,
53 protected router: Router,
54 private confirmService: ConfirmService,
55 private auth: AuthService,
56 private notifier: Notifier,
57 private videoService: VideoService,
58 private videoAdminService: VideoAdminService,
59 private videoBlockService: VideoBlockService
65 return this.auth.getUser()
71 this.inputFilters = this.videoAdminService.buildAdminInputFilter()
73 this.bulkVideoActions = [
76 label: $localize`Delete`,
77 handler: videos => this.removeVideos(videos),
78 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO),
82 label: $localize`Block`,
83 handler: videos => this.videoBlockModal.show(videos),
84 isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted),
88 label: $localize`Unblock`,
89 handler: videos => this.unblockVideos(videos),
90 isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted),
96 label: $localize`Run HLS transcoding`,
97 handler: videos => this.runTranscoding(videos, 'hls'),
98 isDisplayed: videos => videos.every(v => v.canRunTranscoding(this.authUser)),
102 label: $localize`Run WebTorrent transcoding`,
103 handler: videos => this.runTranscoding(videos, 'webtorrent'),
104 isDisplayed: videos => videos.every(v => v.canRunTranscoding(this.authUser)),
108 label: $localize`Delete HLS files`,
109 handler: videos => this.removeVideoFiles(videos, 'hls'),
110 isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)),
114 label: $localize`Delete WebTorrent files`,
115 handler: videos => this.removeVideoFiles(videos, 'webtorrent'),
116 isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)),
124 return 'VideoListComponent'
127 isInSelectionMode () {
128 return this.selectedVideos.length !== 0
131 getPrivacyBadgeClass (video: Video) {
132 if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green'
134 return 'badge-yellow'
137 isUnpublished (video: Video) {
138 return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED
141 isAccountBlocked (video: Video) {
142 return video.blockedOwner
145 isServerBlocked (video: Video) {
146 return video.blockedServer
149 isVideoBlocked (video: Video) {
150 return video.blacklisted
153 isImport (video: Video) {
154 return video.state.id === VideoState.TO_IMPORT
157 isHLS (video: Video) {
158 const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
161 return p.files.length !== 0
164 isWebTorrent (video: Video) {
165 return video.files.length !== 0
168 getFilesSize (video: Video) {
169 let files = video.files
171 if (this.isHLS(video)) {
172 files = files.concat(video.streamingPlaylists[0].files)
175 return files.reduce((p, f) => p += f.size, 0)
179 this.selectedVideos = []
183 this.videoAdminService.getAdminVideos({
184 pagination: this.pagination,
187 }).pipe(finalize(() => this.loading = false))
189 next: resultList => {
190 this.videos = resultList.data
191 this.totalRecords = resultList.total
194 error: err => this.notifier.error(err.message)
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
203 this.videoService.removeVideo(videos.map(v => v.id))
206 this.notifier.success($localize`Deleted ${videos.length} videos.`)
210 error: err => this.notifier.error(err.message)
214 private unblockVideos (videos: Video[]) {
215 this.videoBlockService.unblockVideo(videos.map(v => v.id))
218 this.notifier.success($localize`Unblocked ${videos.length} videos.`)
222 error: err => this.notifier.error(err.message)
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?`
231 const res = await this.confirmService.confirm(message, $localize`Delete`)
232 if (res === false) return
234 this.videoService.removeVideoFiles(videos.map(v => v.id), type)
237 this.notifier.success($localize`Files were removed.`)
241 error: err => this.notifier.error(err.message)
245 private runTranscoding (videos: Video[], type: 'hls' | 'webtorrent') {
246 this.videoService.runTranscoding(videos.map(v => v.id), type)
249 this.notifier.success($localize`Transcoding jobs created.`)
254 error: err => this.notifier.error(err.message)