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