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