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 = {
49 protected route: ActivatedRoute,
50 protected router: Router,
51 private confirmService: ConfirmService,
52 private auth: AuthService,
53 private notifier: Notifier,
54 private videoService: VideoService,
55 private videoAdminService: VideoAdminService,
56 private videoBlockService: VideoBlockService
62 return this.auth.getUser()
68 this.inputFilters = this.videoAdminService.buildAdminInputFilter()
70 this.bulkVideoActions = [
73 label: $localize`Delete`,
74 handler: videos => this.removeVideos(videos),
75 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO),
79 label: $localize`Block`,
80 handler: videos => this.videoBlockModal.show(videos),
81 isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted),
85 label: $localize`Unblock`,
86 handler: videos => this.unblockVideos(videos),
87 isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted),
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()),
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()),
109 return 'VideoListComponent'
112 isInSelectionMode () {
113 return this.selectedVideos.length !== 0
116 getPrivacyBadgeClass (video: Video) {
117 if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green'
119 return 'badge-yellow'
122 isUnpublished (video: Video) {
123 return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED
126 isAccountBlocked (video: Video) {
127 return video.blockedOwner
130 isServerBlocked (video: Video) {
131 return video.blockedServer
134 isVideoBlocked (video: Video) {
135 return video.blacklisted
138 isImport (video: Video) {
139 return video.state.id === VideoState.TO_IMPORT
142 isHLS (video: Video) {
143 const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
146 return p.files.length !== 0
149 isWebTorrent (video: Video) {
150 return video.files.length !== 0
153 getFilesSize (video: Video) {
154 let files = video.files
156 if (this.isHLS(video)) {
157 files = files.concat(video.streamingPlaylists[0].files)
160 return files.reduce((p, f) => p += f.size, 0)
164 this.selectedVideos = []
168 this.videoAdminService.getAdminVideos({
169 pagination: this.pagination,
172 }).pipe(finalize(() => this.loading = false))
174 next: resultList => {
175 this.videos = resultList.data
176 this.totalRecords = resultList.total
179 error: err => this.notifier.error(err.message)
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
188 this.videoService.removeVideo(videos.map(v => v.id))
191 this.notifier.success($localize`Deleted ${videos.length} videos.`)
195 error: err => this.notifier.error(err.message)
199 private unblockVideos (videos: Video[]) {
200 this.videoBlockService.unblockVideo(videos.map(v => v.id))
203 this.notifier.success($localize`Unblocked ${videos.length} videos.`)
207 error: err => this.notifier.error(err.message)
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?`
216 const res = await this.confirmService.confirm(message, $localize`Delete`)
217 if (res === false) return
219 this.videoService.removeVideoFiles(videos.map(v => v.id), type)
222 this.notifier.success($localize`Files were removed.`)
226 error: err => this.notifier.error(err.message)