1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { AuthService, AuthUser, CanComponentDeactivate, HooksService, ServerService } from '@app/core'
4 import { HTMLServerConfig } from '@shared/models'
5 import { VideoEditType } from './shared/video-edit.type'
6 import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
7 import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
8 import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
9 import { VideoUploadComponent } from './video-add-components/video-upload.component'
12 selector: 'my-videos-add',
13 templateUrl: './video-add.component.html',
14 styleUrls: [ './video-add.component.scss' ]
16 export class VideoAddComponent implements OnInit, CanComponentDeactivate {
17 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
18 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
19 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
20 @ViewChild('videoGoLive') videoGoLive: VideoGoLiveComponent
24 secondStepType: VideoEditType
32 quotaLeftDaily: string
36 private serverConfig: HTMLServerConfig
39 private auth: AuthService,
40 private hooks: HooksService,
41 private serverService: ServerService,
42 private route: ActivatedRoute,
43 private router: Router
46 get isContactFormEnabled () {
47 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
50 get userInformationLoaded () {
51 return this.auth.userInformationLoaded
55 this.user = this.auth.getUser()
57 this.serverConfig = this.serverService.getHTMLConfig()
59 this.user = this.auth.getUser()
61 if (this.route.snapshot.fragment) {
62 this.onNavChange(this.route.snapshot.fragment)
65 this.buildUploadMessages()
68 private async buildUploadMessages () {
69 // eslint-disable-next-line max-len
70 const noQuota = $localize`Sorry, the upload feature is disabled for your account. If you want to add videos, an admin must unlock your quota.`
71 // eslint-disable-next-line max-len
72 const autoBlock = $localize`Uploaded videos are reviewed before publishing for your account. If you want to add videos without moderation review, an admin must turn off your videos auto-block.`
73 // eslint-disable-next-line max-len
74 const quotaLeftDaily = $localize`Your daily video quota is insufficient. If you want to add more videos, you must wait for 24 hours or an admin must increase your daily quota.`
75 // eslint-disable-next-line max-len
76 const quotaLeft = $localize`Your video quota is insufficient. If you want to add more videos, an admin must increase your quota.`
78 const uploadMessages = {
85 this.uploadMessages = await this.hooks.wrapObject(uploadMessages, 'common', 'filter:upload-page.alert-messages.edit.result')
88 onNavChange (newActiveNav: string) {
89 this.activeNav = newActiveNav
91 this.router.navigate([], { fragment: this.activeNav })
94 onFirstStepDone (type: VideoEditType, videoName: string) {
95 this.secondStepType = type
96 this.videoName = videoName
100 this.videoName = undefined
101 this.secondStepType = undefined
104 @HostListener('window:beforeunload', [ '$event' ])
105 onUnload (event: any) {
106 const { text, canDeactivate } = this.canDeactivate()
108 if (canDeactivate) return
110 event.returnValue = text
114 canDeactivate (): { canDeactivate: boolean, text?: string} {
115 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
116 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
117 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
119 return { canDeactivate: true }
122 isVideoImportHttpEnabled () {
123 return this.serverConfig.import.videos.http.enabled
126 isVideoImportTorrentEnabled () {
127 return this.serverConfig.import.videos.torrent.enabled
130 isVideoLiveEnabled () {
131 return this.serverConfig.live.enabled
135 return !!this.secondStepType
139 return this.user.username === 'root'