]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add.component.ts
Bumped to version v5.2.1
[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'
52a354ab
MK
3import {
4 AuthService,
5 AuthUser,
6 CanComponentDeactivate,
7 HooksService,
8 ServerService,
9 UserService
10} from '@app/core'
2989628b 11import { HTMLServerConfig } from '@shared/models'
c6c0fa6c
C
12import { VideoEditType } from './shared/video-edit.type'
13import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
67ed6552
C
14import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
15import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
16import { VideoUploadComponent } from './video-add-components/video-upload.component'
1553e15d 17
dc8bc31b
C
18@Component({
19 selector: 'my-videos-add',
27e1a06c 20 templateUrl: './video-add.component.html',
fbad87b0 21 styleUrls: [ './video-add.component.scss' ]
dc8bc31b 22})
ba430d75 23export class VideoAddComponent implements OnInit, CanComponentDeactivate {
2f5d2ec5
C
24 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
25 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
26 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
c6c0fa6c 27 @ViewChild('videoGoLive') videoGoLive: VideoGoLiveComponent
bfb3a98f 28
dfe3f7b7 29 user: AuthUser = null
2e7f2627 30
c6c0fa6c 31 secondStepType: VideoEditType
fbad87b0 32 videoName: string
3914a50b
C
33
34 activeNav: string
35
4e1592da
MK
36 uploadMessages: {
37 noQuota: string
38 autoBlock: string
39 quotaLeftDaily: string
40 quotaLeft: string
41 }
42
52a354ab
MK
43 hasNoQuotaLeft = false
44 hasNoQuotaLeftDaily = false
45
8e7442d0 46 serverConfig: HTMLServerConfig
bbe0f064 47
5d08a6a7 48 constructor (
cd3d847d 49 private auth: AuthService,
52a354ab 50 private userService: UserService,
4e1592da 51 private hooks: HooksService,
3914a50b
C
52 private serverService: ServerService,
53 private route: ActivatedRoute,
54 private router: Router
5d08a6a7
C
55 ) {}
56
4e1592da
MK
57 get isContactFormEnabled () {
58 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
59 }
60
2e7f2627
K
61 get userInformationLoaded () {
62 return this.auth.userInformationLoaded
63 }
64
ba430d75 65 ngOnInit () {
2e7f2627
K
66 this.user = this.auth.getUser()
67
2989628b 68 this.serverConfig = this.serverService.getHTMLConfig()
dfe3f7b7 69
3914a50b
C
70 if (this.route.snapshot.fragment) {
71 this.onNavChange(this.route.snapshot.fragment)
72 }
4e1592da
MK
73
74 this.buildUploadMessages()
52a354ab
MK
75
76 this.userService.getMyVideoQuotaUsed()
77 .subscribe(data => {
78 // videoQuota left lower than 10%
79 if (data.videoQuotaUsed > this.user.videoQuota * 0.9) {
80 this.hasNoQuotaLeft = true
81 }
82
83 // unlimited videoQuota
84 if (this.user.videoQuota === -1) {
85 this.hasNoQuotaLeft = false
86 }
87
88 // videoQuotaDaily left lower than 10%
89 if (data.videoQuotaUsedDaily > this.user.videoQuotaDaily * 0.9) {
90 this.hasNoQuotaLeftDaily = true
91 }
92
93 // unlimited videoQuotaDaily
94 if (this.user.videoQuotaDaily === -1) {
95 this.hasNoQuotaLeftDaily = false
96 }
97 })
4e1592da
MK
98 }
99
100 private async buildUploadMessages () {
101 // eslint-disable-next-line max-len
102 const noQuota = $localize`Sorry, the upload feature is disabled for your account. If you want to add videos, an admin must unlock your quota.`
103 // eslint-disable-next-line max-len
104 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.`
105 // eslint-disable-next-line max-len
106 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.`
107 // eslint-disable-next-line max-len
108 const quotaLeft = $localize`Your video quota is insufficient. If you want to add more videos, an admin must increase your quota.`
109
110 const uploadMessages = {
111 noQuota,
112 autoBlock,
113 quotaLeftDaily,
114 quotaLeft
115 }
116
59c8902a 117 this.uploadMessages = await this.hooks.wrapObject(uploadMessages, 'common', 'filter:upload.messages.create.result')
3914a50b
C
118 }
119
120 onNavChange (newActiveNav: string) {
121 this.activeNav = newActiveNav
122
123 this.router.navigate([], { fragment: this.activeNav })
ba430d75
C
124 }
125
c6c0fa6c 126 onFirstStepDone (type: VideoEditType, videoName: string) {
fbad87b0
C
127 this.secondStepType = type
128 this.videoName = videoName
f6a043df
C
129 }
130
7373507f
C
131 onError () {
132 this.videoName = undefined
133 this.secondStepType = undefined
134 }
135
674a66bb
C
136 @HostListener('window:beforeunload', [ '$event' ])
137 onUnload (event: any) {
138 const { text, canDeactivate } = this.canDeactivate()
139
140 if (canDeactivate) return
141
142 event.returnValue = text
143 return text
144 }
145
7dcd7d81 146 canDeactivate (): { canDeactivate: boolean, text?: string } {
221d876f 147 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
047559af 148 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 149 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
c6c0fa6c 150 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
40e87e9e 151
fbad87b0 152 return { canDeactivate: true }
27e1a06c 153 }
5d08a6a7 154
ce33919c 155 isVideoImportHttpEnabled () {
ba430d75 156 return this.serverConfig.import.videos.http.enabled
ce33919c
C
157 }
158
159 isVideoImportTorrentEnabled () {
ba430d75 160 return this.serverConfig.import.videos.torrent.enabled
5d08a6a7 161 }
cd3d847d 162
c6c0fa6c
C
163 isVideoLiveEnabled () {
164 return this.serverConfig.live.enabled
165 }
166
cd3d847d
C
167 isInSecondStep () {
168 return !!this.secondStepType
169 }
170
171 isRootUser () {
dfe3f7b7 172 return this.user.username === 'root'
cd3d847d 173 }
dc8bc31b 174}