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 title: $localize`Advanced filters`,
34 queryParams: { search: 'type:auto' },
35 label: $localize`Automatic blocks`
38 queryParams: { search: 'type:manual' },
39 label: $localize`Manual blocks`
46 protected route: ActivatedRoute,
47 protected router: Router,
48 private notifier: Notifier,
49 private serverService: ServerService,
50 private confirmService: ConfirmService,
51 private videoBlocklistService: VideoBlockService,
52 private markdownRenderer: MarkdownService,
53 private sanitizer: DomSanitizer,
54 private videoService: VideoService
58 this.videoBlocklistActions = [
61 label: $localize`Internal actions`,
63 isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
66 label: $localize`Switch video block to manual`,
67 handler: videoBlock => {
68 this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe(
69 switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true))
72 this.notifier.success($localize`Video ${videoBlock.video.name} switched to manual block.`)
76 error: err => this.notifier.error(err.message)
79 isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
84 label: $localize`Actions for the video`,
88 label: $localize`Unblock`,
89 handler: videoBlock => this.unblockVideo(videoBlock)
93 label: $localize`Delete`,
94 handler: async videoBlock => {
95 const res = await this.confirmService.confirm(
96 $localize`Do you really want to delete this video?`,
99 if (res === false) return
101 this.videoService.removeVideo(videoBlock.video.id)
103 next: () => this.notifier.success($localize`Video deleted.`),
105 error: err => this.notifier.error(err.message)
114 const serverConfig = this.serverService.getHTMLConfig()
116 // Don't filter if auto-blacklist is not enabled as this will be the only list
117 if (serverConfig.autoBlacklist.videos.ofUsers.enabled) {
118 this.blocklistTypeFilter = VideoBlacklistType.MANUAL
125 return 'VideoBlockListComponent'
128 getVideoUrl (videoBlock: VideoBlacklist) {
129 return Video.buildWatchUrl(videoBlock.video)
132 toHtml (text: string) {
133 return this.markdownRenderer.textMarkdownToHTML(text)
136 async unblockVideo (entry: VideoBlacklist) {
137 const confirmMessage = $localize`Do you really want to unblock this video? It will be available again in the videos list.`
139 const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`)
140 if (res === false) return
142 this.videoBlocklistService.unblockVideo(entry.video.id)
145 this.notifier.success($localize`Video ${entry.video.name} unblocked.`)
149 error: err => this.notifier.error(err.message)
153 getVideoEmbed (entry: VideoBlacklist) {
154 return buildVideoOrPlaylistEmbed(
156 url: buildVideoEmbedLink(entry.video, environment.originServerUrl),
165 protected reloadData () {
166 this.videoBlocklistService.listBlocks({
167 pagination: this.pagination,
172 next: async resultList => {
173 this.totalRecords = resultList.total
175 this.blocklist = resultList.data
177 for (const element of this.blocklist) {
178 Object.assign(element, {
179 reasonHtml: await this.toHtml(element.reason),
180 embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element))
185 error: err => this.notifier.error(err.message)