1 import { SortMeta } from 'primeng/api'
2 import { switchMap } from 'rxjs/operators'
3 import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils'
4 import { environment } from 'src/environments/environment'
5 import { Component, OnInit } from '@angular/core'
6 import { DomSanitizer } from '@angular/platform-browser'
7 import { ActivatedRoute, Router } from '@angular/router'
8 import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
9 import { AdvancedInputFilter } from '@app/shared/shared-forms'
10 import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
11 import { VideoBlockService } from '@app/shared/shared-moderation'
12 import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils'
13 import { VideoBlacklist, VideoBlacklistType } from '@shared/models'
16 selector: 'my-video-block-list',
17 templateUrl: './video-block-list.component.html',
18 styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ]
20 export class VideoBlockListComponent extends RestTable implements OnInit {
21 blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = []
23 sort: SortMeta = { field: 'createdAt', order: -1 }
24 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
25 blocklistTypeFilter: VideoBlacklistType = undefined
27 videoBlocklistActions: DropdownAction<VideoBlacklist>[][] = []
29 inputFilters: AdvancedInputFilter[] = [
31 queryParams: { 'search': 'type:auto' },
32 label: $localize`Automatic blocks`
35 queryParams: { 'search': 'type:manual' },
36 label: $localize`Manual blocks`
41 protected route: ActivatedRoute,
42 protected router: Router,
43 private notifier: Notifier,
44 private serverService: ServerService,
45 private confirmService: ConfirmService,
46 private videoBlocklistService: VideoBlockService,
47 private markdownRenderer: MarkdownService,
48 private sanitizer: DomSanitizer,
49 private videoService: VideoService
53 this.videoBlocklistActions = [
56 label: $localize`Internal actions`,
58 isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
61 label: $localize`Switch video block to manual`,
62 handler: videoBlock => {
63 this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe(
64 switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true))
67 this.notifier.success($localize`Video ${videoBlock.video.name} switched to manual block.`)
71 err => this.notifier.error(err.message)
74 isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
79 label: $localize`Actions for the video`,
83 label: $localize`Unblock`,
84 handler: videoBlock => this.unblockVideo(videoBlock)
88 label: $localize`Delete`,
89 handler: async videoBlock => {
90 const res = await this.confirmService.confirm(
91 $localize`Do you really want to delete this video?`,
94 if (res === false) return
96 this.videoService.removeVideo(videoBlock.video.id)
99 this.notifier.success($localize`Video deleted.`)
102 err => this.notifier.error(err.message)
111 const serverConfig = this.serverService.getHTMLConfig()
113 // Don't filter if auto-blacklist is not enabled as this will be the only list
114 if (serverConfig.autoBlacklist.videos.ofUsers.enabled) {
115 this.blocklistTypeFilter = VideoBlacklistType.MANUAL
122 return 'VideoBlockListComponent'
125 getVideoUrl (videoBlock: VideoBlacklist) {
126 return Video.buildWatchUrl(videoBlock.video)
129 toHtml (text: string) {
130 return this.markdownRenderer.textMarkdownToHTML(text)
133 async unblockVideo (entry: VideoBlacklist) {
134 const confirmMessage = $localize`Do you really want to unblock this video? It will be available again in the videos list.`
136 const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`)
137 if (res === false) return
139 this.videoBlocklistService.unblockVideo(entry.video.id).subscribe(
141 this.notifier.success($localize`Video ${entry.video.name} unblocked.`)
145 err => this.notifier.error(err.message)
149 getVideoEmbed (entry: VideoBlacklist) {
150 return buildVideoOrPlaylistEmbed(
152 url: buildVideoEmbedLink(entry.video, environment.originServerUrl),
161 protected reloadData () {
162 this.videoBlocklistService.listBlocks({
163 pagination: this.pagination,
168 async resultList => {
169 this.totalRecords = resultList.total
171 this.blocklist = resultList.data
173 for (const element of this.blocklist) {
174 Object.assign(element, {
175 reasonHtml: await this.toHtml(element.reason),
176 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element))
181 err => this.notifier.error(err.message)