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