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