1 import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'
2 import { AuthService, ConfirmService, Notifier, ScreenService, ServerService } from '@app/core'
3 import { BlocklistService, VideoBlockComponent, VideoBlockService, VideoReportComponent } from '@app/shared/shared-moderation'
4 import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'
5 import { VideoCaption } from '@shared/models'
15 } from '../shared-main'
16 import { LiveStreamInformationComponent } from '../shared-video-live'
17 import { VideoAddToPlaylistComponent } from '../shared-video-playlist'
18 import { VideoDownloadComponent } from './video-download.component'
20 export type VideoActionsDisplayType = {
37 selector: 'my-video-actions-dropdown',
38 templateUrl: './video-actions-dropdown.component.html',
39 styleUrls: [ './video-actions-dropdown.component.scss' ]
41 export class VideoActionsDropdownComponent implements OnChanges {
42 @ViewChild('playlistDropdown') playlistDropdown: NgbDropdown
43 @ViewChild('playlistAdd') playlistAdd: VideoAddToPlaylistComponent
45 @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
46 @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
47 @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
48 @ViewChild('liveStreamInformationModal') liveStreamInformationModal: LiveStreamInformationComponent
50 @Input() video: Video | VideoDetails
51 @Input() videoCaptions: VideoCaption[] = []
53 @Input() displayOptions: VideoActionsDisplayType = {
68 @Input() placement = 'left'
69 @Input() moreActions: DropdownAction<{ video: Video }>[][] = []
71 @Input() label: string
73 @Input() buttonStyled = false
74 @Input() buttonSize: DropdownButtonSize = 'normal'
75 @Input() buttonDirection: DropdownDirection = 'vertical'
77 @Output() videoFilesRemoved = new EventEmitter()
78 @Output() videoRemoved = new EventEmitter()
79 @Output() videoUnblocked = new EventEmitter()
80 @Output() videoBlocked = new EventEmitter()
81 @Output() videoAccountMuted = new EventEmitter()
82 @Output() transcodingCreated = new EventEmitter()
83 @Output() modalOpened = new EventEmitter()
85 videoActions: DropdownAction<{ video: Video }>[][] = []
87 private loaded = false
90 private authService: AuthService,
91 private notifier: Notifier,
92 private confirmService: ConfirmService,
93 private blocklistService: BlocklistService,
94 private videoBlocklistService: VideoBlockService,
95 private screenService: ScreenService,
96 private videoService: VideoService,
97 private redundancyService: RedundancyService,
98 private serverService: ServerService
102 return this.authService.getUser()
108 if (this.playlistAdd) this.playlistAdd.reload()
115 return this.authService.isLoggedIn()
118 loadDropdownInformation () {
119 if (!this.isUserLoggedIn() || this.loaded === true) return
123 if (this.displayOptions.playlist) this.playlistAdd.load()
128 showDownloadModal () {
129 this.modalOpened.emit()
131 this.videoDownloadModal.show(this.video as VideoDetails, this.videoCaptions)
135 this.modalOpened.emit()
137 this.videoReportModal.show()
141 this.modalOpened.emit()
143 this.videoBlockModal.show([ this.video ])
146 showLiveInfoModal (video: Video) {
147 this.modalOpened.emit()
149 this.liveStreamInformationModal.show(video)
152 /* Actions checker */
154 isVideoUpdatable () {
155 return this.video.isUpdatableBy(this.user)
159 return this.video.isEditableBy(this.user, this.serverService.getHTMLConfig().videoStudio.enabled)
162 isVideoStatsAvailable () {
163 return this.video.canSeeStats(this.user)
166 isVideoRemovable () {
167 return this.video.isRemovableBy(this.user)
170 isVideoBlockable () {
171 return this.video.isBlockableBy(this.user)
174 isVideoUnblockable () {
175 return this.video.isUnblockableBy(this.user)
178 isVideoLiveInfoAvailable () {
179 return this.video.isLiveInfoAvailableBy(this.user)
182 isVideoDownloadable () {
184 this.video.isLive !== true &&
185 this.video instanceof VideoDetails &&
186 this.video.downloadEnabled
189 canVideoBeDuplicated () {
190 return !this.video.isLive && this.video.canBeDuplicatedBy(this.user)
193 isVideoAccountMutable () {
194 return this.video.account.id !== this.user.account.id
197 canRemoveVideoFiles () {
198 return this.video.canRemoveFiles(this.user)
201 canRunTranscoding () {
202 return this.video.canRunTranscoding(this.user)
205 /* Action handlers */
207 async unblockVideo () {
208 const confirmMessage = $localize`Do you really want to unblock ${this.video.name}? It will be available again in the videos list.`
210 const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock ${this.video.name}`)
211 if (res === false) return
213 this.videoBlocklistService.unblockVideo(this.video.id)
216 this.notifier.success($localize`Video ${this.video.name} unblocked.`)
218 this.video.blacklisted = false
219 this.video.blacklistedReason = null
221 this.videoUnblocked.emit()
224 error: err => this.notifier.error(err.message)
228 async removeVideo () {
229 this.modalOpened.emit()
231 let message = $localize`Do you really want to delete ${this.video.name}?`
232 if (this.video.isLive) {
233 message += ' ' + $localize`The live stream will be automatically terminated and replays won't be saved.`
236 const res = await this.confirmService.confirm(message, $localize`Delete ${this.video.name}`)
237 if (res === false) return
239 this.videoService.removeVideo(this.video.id)
242 this.notifier.success($localize`Video ${this.video.name} deleted.`)
243 this.videoRemoved.emit()
246 error: err => this.notifier.error(err.message)
251 this.redundancyService.addVideoRedundancy(this.video)
254 const message = $localize`${this.video.name} will be duplicated by your instance.`
255 this.notifier.success(message)
258 error: err => this.notifier.error(err.message)
262 muteVideoAccount () {
263 const params = { nameWithHost: Actor.CREATE_BY_STRING(this.video.account.name, this.video.account.host) }
265 this.blocklistService.blockAccountByUser(params)
268 this.notifier.success($localize`Account ${params.nameWithHost} muted.`)
269 this.videoAccountMuted.emit()
272 error: err => this.notifier.error(err.message)
276 async removeVideoFiles (video: Video, type: 'hls' | 'webtorrent') {
277 const confirmMessage = $localize`Do you really want to remove "${this.video.name}" files?`
279 const res = await this.confirmService.confirm(confirmMessage, $localize`Remove "${this.video.name}" files`)
280 if (res === false) return
282 this.videoService.removeVideoFiles([ video.id ], type)
285 this.notifier.success($localize`Removed files of ${video.name}.`)
286 this.videoFilesRemoved.emit()
289 error: err => this.notifier.error(err.message)
293 runTranscoding (video: Video, type: 'hls' | 'webtorrent') {
294 this.videoService.runTranscoding([ video.id ], type)
297 this.notifier.success($localize`Transcoding jobs created for ${video.name}.`)
298 this.transcodingCreated.emit()
301 error: err => this.notifier.error(err.message)
306 this.videoBlocked.emit()
309 getPlaylistDropdownPlacement () {
310 if (this.screenService.isInSmallView()) {
311 return 'bottom-right'
314 return 'bottom-left bottom-right'
317 private buildActions () {
318 this.videoActions = [
321 label: $localize`Save to playlist`,
322 handler: () => this.playlistDropdown.toggle(),
323 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist,
324 iconName: 'playlist-add'
327 [ // actions regarding the video
329 label: $localize`Download`,
330 handler: () => this.showDownloadModal(),
331 isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(),
335 label: $localize`Display live information`,
336 handler: ({ video }) => this.showLiveInfoModal(video),
337 isDisplayed: () => this.displayOptions.liveInfo && this.isVideoLiveInfoAvailable(),
341 label: $localize`Update`,
342 linkBuilder: ({ video }) => [ '/videos/update', video.uuid ],
344 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable()
347 label: $localize`Studio`,
348 linkBuilder: ({ video }) => [ '/studio/edit', video.uuid ],
350 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.studio && this.isVideoEditable()
353 label: $localize`Stats`,
354 linkBuilder: ({ video }) => [ '/stats/videos', video.uuid ],
356 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.stats && this.isVideoStatsAvailable()
359 label: $localize`Block`,
360 handler: () => this.showBlockModal(),
362 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable()
365 label: $localize`Unblock`,
366 handler: () => this.unblockVideo(),
368 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable()
371 label: $localize`Mirror`,
372 handler: () => this.duplicateVideo(),
373 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(),
374 iconName: 'cloud-download'
377 label: $localize`Delete`,
378 handler: () => this.removeVideo(),
379 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(),
383 label: $localize`Report`,
384 handler: () => this.showReportModal(),
385 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report,
391 label: $localize`Run HLS transcoding`,
392 handler: ({ video }) => this.runTranscoding(video, 'hls'),
393 isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
397 label: $localize`Run WebTorrent transcoding`,
398 handler: ({ video }) => this.runTranscoding(video, 'webtorrent'),
399 isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
403 label: $localize`Delete HLS files`,
404 handler: ({ video }) => this.removeVideoFiles(video, 'hls'),
405 isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
409 label: $localize`Delete WebTorrent files`,
410 handler: ({ video }) => this.removeVideoFiles(video, 'webtorrent'),
411 isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
415 [ // actions regarding the account/its server
417 label: $localize`Mute account`,
418 handler: () => this.muteVideoAccount(),
419 isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.mute && this.isVideoAccountMutable(),
425 this.videoActions = this.videoActions.concat(this.moreActions)