]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/overview/videos/video-list.component.ts
Support videos stats in client
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / videos / video-list.component.ts
index 0f98a5d33b5d698ff1541caa963f1de828d3dee7..82ff372aa4252984bf4be7ec73943666544328d6 100644 (file)
@@ -1,10 +1,11 @@
 import { SortMeta } from 'primeng/api'
 import { finalize } from 'rxjs/operators'
-import { Component, OnInit } from '@angular/core'
+import { Component, OnInit, ViewChild } 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 { VideoBlockComponent, VideoBlockService } from '@app/shared/shared-moderation'
 import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
 import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
 import { VideoAdminService } from './video-admin.service'
@@ -15,6 +16,8 @@ import { VideoAdminService } from './video-admin.service'
   styleUrls: [ './video-list.component.scss' ]
 })
 export class VideoListComponent extends RestTable implements OnInit {
+  @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
+
   videos: Video[] = []
 
   totalRecords = 0
@@ -36,7 +39,11 @@ export class VideoListComponent extends RestTable implements OnInit {
     report: false,
     duplicate: true,
     mute: true,
-    liveInfo: false
+    liveInfo: false,
+    removeFiles: true,
+    transcoding: true,
+    studio: true,
+    stats: true
   }
 
   loading = true
@@ -48,7 +55,8 @@ export class VideoListComponent extends RestTable implements OnInit {
     private auth: AuthService,
     private notifier: Notifier,
     private videoService: VideoService,
-    private videoAdminService: VideoAdminService
+    private videoAdminService: VideoAdminService,
+    private videoBlockService: VideoBlockService
   ) {
     super()
   }
@@ -67,7 +75,46 @@ export class VideoListComponent extends RestTable implements OnInit {
         {
           label: $localize`Delete`,
           handler: videos => this.removeVideos(videos),
-          isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
+          isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO),
+          iconName: 'delete'
+        },
+        {
+          label: $localize`Block`,
+          handler: videos => this.videoBlockModal.show(videos),
+          isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted),
+          iconName: 'no'
+        },
+        {
+          label: $localize`Unblock`,
+          handler: videos => this.unblockVideos(videos),
+          isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted),
+          iconName: 'undo'
+        }
+      ],
+      [
+        {
+          label: $localize`Run HLS transcoding`,
+          handler: videos => this.runTranscoding(videos, 'hls'),
+          isDisplayed: videos => videos.every(v => v.canRunTranscoding(this.authUser)),
+          iconName: 'cog'
+        },
+        {
+          label: $localize`Run WebTorrent transcoding`,
+          handler: videos => this.runTranscoding(videos, 'webtorrent'),
+          isDisplayed: videos => videos.every(v => v.canRunTranscoding(this.authUser)),
+          iconName: 'cog'
+        },
+        {
+          label: $localize`Delete HLS files`,
+          handler: videos => this.removeVideoFiles(videos, 'hls'),
+          isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)),
+          iconName: 'delete'
+        },
+        {
+          label: $localize`Delete WebTorrent files`,
+          handler: videos => this.removeVideoFiles(videos, 'webtorrent'),
+          isDisplayed: videos => videos.every(v => v.canRemoveFiles(this.authUser)),
+          iconName: 'delete'
         }
       ]
     ]
@@ -81,10 +128,6 @@ export class VideoListComponent extends RestTable implements OnInit {
     return this.selectedVideos.length !== 0
   }
 
-  onVideoRemoved () {
-    this.reloadData()
-  }
-
   getPrivacyBadgeClass (video: Video) {
     if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green'
 
@@ -132,7 +175,7 @@ export class VideoListComponent extends RestTable implements OnInit {
     return files.reduce((p, f) => p += f.size, 0)
   }
 
-  protected reloadData () {
+  reloadData () {
     this.selectedVideos = []
 
     this.loading = true
@@ -160,7 +203,51 @@ export class VideoListComponent extends RestTable implements OnInit {
     this.videoService.removeVideo(videos.map(v => v.id))
       .subscribe({
         next: () => {
-          this.notifier.success($localize`${videos.length} videos deleted.`)
+          this.notifier.success($localize`Deleted ${videos.length} videos.`)
+          this.reloadData()
+        },
+
+        error: err => this.notifier.error(err.message)
+      })
+  }
+
+  private unblockVideos (videos: Video[]) {
+    this.videoBlockService.unblockVideo(videos.map(v => v.id))
+      .subscribe({
+        next: () => {
+          this.notifier.success($localize`Unblocked ${videos.length} videos.`)
+          this.reloadData()
+        },
+
+        error: err => this.notifier.error(err.message)
+      })
+  }
+
+  private async removeVideoFiles (videos: Video[], type: 'hls' | 'webtorrent') {
+    const message = type === 'hls'
+      ? $localize`Are you sure you want to delete ${videos.length} HLS streaming playlists?`
+      : $localize`Are you sure you want to delete WebTorrent files of ${videos.length} videos?`
+
+    const res = await this.confirmService.confirm(message, $localize`Delete`)
+    if (res === false) return
+
+    this.videoService.removeVideoFiles(videos.map(v => v.id), type)
+      .subscribe({
+        next: () => {
+          this.notifier.success($localize`Files were removed.`)
+          this.reloadData()
+        },
+
+        error: err => this.notifier.error(err.message)
+      })
+  }
+
+  private runTranscoding (videos: Video[], type: 'hls' | 'webtorrent') {
+    this.videoService.runTranscoding(videos.map(v => v.id), type)
+      .subscribe({
+        next: () => {
+          this.notifier.success($localize`Transcoding jobs created.`)
+
           this.reloadData()
         },