]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-edit/video-add.component.ts
Alert user for low quota and video auto-block on upload page (#4336)
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
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'
10
11 @Component({
12 selector: 'my-videos-add',
13 templateUrl: './video-add.component.html',
14 styleUrls: [ './video-add.component.scss' ]
15 })
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
21
22 user: AuthUser = null
23
24 secondStepType: VideoEditType
25 videoName: string
26
27 activeNav: string
28
29 uploadMessages: {
30 noQuota: string
31 autoBlock: string
32 quotaLeftDaily: string
33 quotaLeft: string
34 }
35
36 private serverConfig: HTMLServerConfig
37
38 constructor (
39 private auth: AuthService,
40 private hooks: HooksService,
41 private serverService: ServerService,
42 private route: ActivatedRoute,
43 private router: Router
44 ) {}
45
46 get isContactFormEnabled () {
47 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
48 }
49
50 get userInformationLoaded () {
51 return this.auth.userInformationLoaded
52 }
53
54 ngOnInit () {
55 this.user = this.auth.getUser()
56
57 this.serverConfig = this.serverService.getHTMLConfig()
58
59 this.user = this.auth.getUser()
60
61 if (this.route.snapshot.fragment) {
62 this.onNavChange(this.route.snapshot.fragment)
63 }
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
85 this.uploadMessages = await this.hooks.wrapObject(uploadMessages, 'common', 'filter:upload-page.alert-messages.edit.result')
86 }
87
88 onNavChange (newActiveNav: string) {
89 this.activeNav = newActiveNav
90
91 this.router.navigate([], { fragment: this.activeNav })
92 }
93
94 onFirstStepDone (type: VideoEditType, videoName: string) {
95 this.secondStepType = type
96 this.videoName = videoName
97 }
98
99 onError () {
100 this.videoName = undefined
101 this.secondStepType = undefined
102 }
103
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} {
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()
118
119 return { canDeactivate: true }
120 }
121
122 isVideoImportHttpEnabled () {
123 return this.serverConfig.import.videos.http.enabled
124 }
125
126 isVideoImportTorrentEnabled () {
127 return this.serverConfig.import.videos.torrent.enabled
128 }
129
130 isVideoLiveEnabled () {
131 return this.serverConfig.live.enabled
132 }
133
134 isInSecondStep () {
135 return !!this.secondStepType
136 }
137
138 isRootUser () {
139 return this.user.username === 'root'
140 }
141 }