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