1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
import { SortMeta } from 'primeng/api'
import { switchMap } from 'rxjs/operators'
import { buildVideoEmbedLink, buildVideoOrPlaylistEmbed, decorateVideoLink } from 'src/assets/player/utils'
import { environment } from 'src/environments/environment'
import { Component, OnInit } from '@angular/core'
import { DomSanitizer } from '@angular/platform-browser'
import { ActivatedRoute, Router } from '@angular/router'
import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
import { VideoBlockService } from '@app/shared/shared-moderation'
import { VideoBlacklist, VideoBlacklistType } from '@shared/models'
@Component({
selector: 'my-video-block-list',
templateUrl: './video-block-list.component.html',
styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ]
})
export class VideoBlockListComponent extends RestTable implements OnInit {
blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = []
totalRecords = 0
sort: SortMeta = { field: 'createdAt', order: -1 }
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
blocklistTypeFilter: VideoBlacklistType = undefined
videoBlocklistActions: DropdownAction<VideoBlacklist>[][] = []
inputFilters: AdvancedInputFilter[] = [
{
queryParams: { 'search': 'type:auto' },
label: $localize`Automatic blocks`
},
{
queryParams: { 'search': 'type:manual' },
label: $localize`Manual blocks`
}
]
constructor (
protected route: ActivatedRoute,
protected router: Router,
private notifier: Notifier,
private serverService: ServerService,
private confirmService: ConfirmService,
private videoBlocklistService: VideoBlockService,
private markdownRenderer: MarkdownService,
private sanitizer: DomSanitizer,
private videoService: VideoService
) {
super()
this.videoBlocklistActions = [
[
{
label: $localize`Internal actions`,
isHeader: true,
isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
},
{
label: $localize`Switch video block to manual`,
handler: videoBlock => {
this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe(
switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true))
).subscribe(
() => {
this.notifier.success($localize`Video ${videoBlock.video.name} switched to manual block.`)
this.reloadData()
},
err => this.notifier.error(err.message)
)
},
isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED
}
],
[
{
label: $localize`Actions for the video`,
isHeader: true
},
{
label: $localize`Unblock`,
handler: videoBlock => this.unblockVideo(videoBlock)
},
{
label: $localize`Delete`,
handler: async videoBlock => {
const res = await this.confirmService.confirm(
$localize`Do you really want to delete this video?`,
$localize`Delete`
)
if (res === false) return
this.videoService.removeVideo(videoBlock.video.id)
.subscribe(
() => {
this.notifier.success($localize`Video deleted.`)
},
err => this.notifier.error(err.message)
)
}
}
]
]
}
ngOnInit () {
const serverConfig = this.serverService.getHTMLConfig()
// Don't filter if auto-blacklist is not enabled as this will be the only list
if (serverConfig.autoBlacklist.videos.ofUsers.enabled) {
this.blocklistTypeFilter = VideoBlacklistType.MANUAL
}
this.initialize()
}
getIdentifier () {
return 'VideoBlockListComponent'
}
getVideoUrl (videoBlock: VideoBlacklist) {
return Video.buildWatchUrl(videoBlock.video)
}
toHtml (text: string) {
return this.markdownRenderer.textMarkdownToHTML(text)
}
async unblockVideo (entry: VideoBlacklist) {
const confirmMessage = $localize`Do you really want to unblock this video? It will be available again in the videos list.`
const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`)
if (res === false) return
this.videoBlocklistService.unblockVideo(entry.video.id).subscribe(
() => {
this.notifier.success($localize`Video ${entry.video.name} unblocked.`)
this.reloadData()
},
err => this.notifier.error(err.message)
)
}
getVideoEmbed (entry: VideoBlacklist) {
return buildVideoOrPlaylistEmbed(
decorateVideoLink({
url: buildVideoEmbedLink(entry.video, environment.originServerUrl),
title: false,
warningTitle: false
}),
entry.video.name
)
}
protected reloadData () {
this.videoBlocklistService.listBlocks({
pagination: this.pagination,
sort: this.sort,
search: this.search
})
.subscribe(
async resultList => {
this.totalRecords = resultList.total
this.blocklist = resultList.data
for (const element of this.blocklist) {
Object.assign(element, {
reasonHtml: await this.toHtml(element.reason),
embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element))
})
}
},
err => this.notifier.error(err.message)
)
}
}
|