]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add.component.ts
Update upload message filter hook name
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
CommitLineData
ba430d75 1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
3914a50b 2import { ActivatedRoute, Router } from '@angular/router'
4e1592da 3import { AuthService, AuthUser, CanComponentDeactivate, HooksService, ServerService } from '@app/core'
2989628b 4import { HTMLServerConfig } from '@shared/models'
c6c0fa6c
C
5import { VideoEditType } from './shared/video-edit.type'
6import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
67ed6552
C
7import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
8import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
9import { VideoUploadComponent } from './video-add-components/video-upload.component'
1553e15d 10
dc8bc31b
C
11@Component({
12 selector: 'my-videos-add',
27e1a06c 13 templateUrl: './video-add.component.html',
fbad87b0 14 styleUrls: [ './video-add.component.scss' ]
dc8bc31b 15})
ba430d75 16export class VideoAddComponent implements OnInit, CanComponentDeactivate {
2f5d2ec5
C
17 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
18 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
19 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
c6c0fa6c 20 @ViewChild('videoGoLive') videoGoLive: VideoGoLiveComponent
bfb3a98f 21
dfe3f7b7 22 user: AuthUser = null
2e7f2627 23
c6c0fa6c 24 secondStepType: VideoEditType
fbad87b0 25 videoName: string
3914a50b
C
26
27 activeNav: string
28
4e1592da
MK
29 uploadMessages: {
30 noQuota: string
31 autoBlock: string
32 quotaLeftDaily: string
33 quotaLeft: string
34 }
35
2989628b 36 private serverConfig: HTMLServerConfig
bbe0f064 37
5d08a6a7 38 constructor (
cd3d847d 39 private auth: AuthService,
4e1592da 40 private hooks: HooksService,
3914a50b
C
41 private serverService: ServerService,
42 private route: ActivatedRoute,
43 private router: Router
5d08a6a7
C
44 ) {}
45
4e1592da
MK
46 get isContactFormEnabled () {
47 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
48 }
49
2e7f2627
K
50 get userInformationLoaded () {
51 return this.auth.userInformationLoaded
52 }
53
ba430d75 54 ngOnInit () {
2e7f2627
K
55 this.user = this.auth.getUser()
56
2989628b 57 this.serverConfig = this.serverService.getHTMLConfig()
dfe3f7b7
K
58
59 this.user = this.auth.getUser()
3914a50b
C
60
61 if (this.route.snapshot.fragment) {
62 this.onNavChange(this.route.snapshot.fragment)
63 }
4e1592da
MK
64
65 this.buildUploadMessages()
66 }
67
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.`
77
78 const uploadMessages = {
79 noQuota,
80 autoBlock,
81 quotaLeftDaily,
82 quotaLeft
83 }
84
59c8902a 85 this.uploadMessages = await this.hooks.wrapObject(uploadMessages, 'common', 'filter:upload.messages.create.result')
3914a50b
C
86 }
87
88 onNavChange (newActiveNav: string) {
89 this.activeNav = newActiveNav
90
91 this.router.navigate([], { fragment: this.activeNav })
ba430d75
C
92 }
93
c6c0fa6c 94 onFirstStepDone (type: VideoEditType, videoName: string) {
fbad87b0
C
95 this.secondStepType = type
96 this.videoName = videoName
f6a043df
C
97 }
98
7373507f
C
99 onError () {
100 this.videoName = undefined
101 this.secondStepType = undefined
102 }
103
674a66bb
C
104 @HostListener('window:beforeunload', [ '$event' ])
105 onUnload (event: any) {
106 const { text, canDeactivate } = this.canDeactivate()
107
108 if (canDeactivate) return
109
110 event.returnValue = text
111 return text
112 }
113
114 canDeactivate (): { canDeactivate: boolean, text?: string} {
047559af 115 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 116 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
c6c0fa6c 117 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
40e87e9e 118
fbad87b0 119 return { canDeactivate: true }
27e1a06c 120 }
5d08a6a7 121
ce33919c 122 isVideoImportHttpEnabled () {
ba430d75 123 return this.serverConfig.import.videos.http.enabled
ce33919c
C
124 }
125
126 isVideoImportTorrentEnabled () {
ba430d75 127 return this.serverConfig.import.videos.torrent.enabled
5d08a6a7 128 }
cd3d847d 129
c6c0fa6c
C
130 isVideoLiveEnabled () {
131 return this.serverConfig.live.enabled
132 }
133
cd3d847d
C
134 isInSecondStep () {
135 return !!this.secondStepType
136 }
137
138 isRootUser () {
dfe3f7b7 139 return this.user.username === 'root'
cd3d847d 140 }
dc8bc31b 141}