1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
import { SortMeta } from 'primeng/api'
import { finalize } from 'rxjs/operators'
import { Component, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
@Component({
selector: 'my-video-list',
templateUrl: './video-list.component.html',
styleUrls: [ './video-list.component.scss' ]
})
export class VideoListComponent extends RestTable implements OnInit {
videos: Video[] = []
totalRecords = 0
sort: SortMeta = { field: 'publishedAt', order: -1 }
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
bulkVideoActions: DropdownAction<Video[]>[][] = []
selectedVideos: Video[] = []
inputFilters: AdvancedInputFilter[]
videoActionsOptions: VideoActionsDisplayType = {
playlist: false,
download: false,
update: true,
blacklist: true,
delete: true,
report: false,
duplicate: true,
mute: true,
liveInfo: false
}
loading = true
constructor (
protected route: ActivatedRoute,
protected router: Router,
private confirmService: ConfirmService,
private auth: AuthService,
private notifier: Notifier,
private videoService: VideoService
) {
super()
}
get authUser () {
return this.auth.getUser()
}
ngOnInit () {
this.initialize()
this.inputFilters = this.videoService.buildAdminInputFilter()
this.bulkVideoActions = [
[
{
label: $localize`Delete`,
handler: videos => this.removeVideos(videos),
isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
}
]
]
}
getIdentifier () {
return 'VideoListComponent'
}
isInSelectionMode () {
return this.selectedVideos.length !== 0
}
onVideoRemoved () {
this.reloadData()
}
getPrivacyBadgeClass (privacy: VideoPrivacy) {
if (privacy === VideoPrivacy.PUBLIC) return 'badge-blue'
return 'badge-yellow'
}
isUnpublished (state: VideoState) {
return state !== VideoState.LIVE_ENDED && state !== VideoState.PUBLISHED
}
isAccountBlocked (video: Video) {
return video.blockedOwner
}
isServerBlocked (video: Video) {
return video.blockedServer
}
isVideoBlocked (video: Video) {
return video.blacklisted
}
isHLS (video: Video) {
return video.streamingPlaylists.some(p => p.type === VideoStreamingPlaylistType.HLS)
}
isWebTorrent (video: Video) {
return video.files.length !== 0
}
getFilesSize (video: Video) {
let files = video.files
if (this.isHLS(video)) {
files = files.concat(video.streamingPlaylists[0].files)
}
return files.reduce((p, f) => p += f.size, 0)
}
protected reloadData () {
this.selectedVideos = []
this.loading = true
this.videoService.getAdminVideos({
pagination: this.pagination,
sort: this.sort,
search: this.search
}).pipe(finalize(() => this.loading = false))
.subscribe({
next: resultList => {
this.videos = resultList.data
this.totalRecords = resultList.total
},
error: err => this.notifier.error(err.message)
})
}
private async removeVideos (videos: Video[]) {
const message = $localize`Are you sure you want to delete these ${videos.length} videos?`
const res = await this.confirmService.confirm(message, $localize`Delete`)
if (res === false) return
this.videoService.removeVideo(videos.map(v => v.id))
.subscribe({
next: () => {
this.notifier.success($localize`${videos.length} videos deleted.`)
this.reloadData()
},
error: err => this.notifier.error(err.message)
})
}
}
|