2019-12-18 14:31:54 +00:00
import { Component , HostListener , OnInit , ViewChild } from '@angular/core'
2021-05-11 13:03:30 +00:00
import { ActivatedRoute , Router } from '@angular/router'
2021-08-26 06:40:18 +00:00
import {
AuthService ,
AuthUser ,
CanComponentDeactivate ,
HooksService ,
ServerService ,
UserService
} from '@app/core'
2021-06-04 11:31:41 +00:00
import { HTMLServerConfig } from '@shared/models'
2020-09-17 07:20:52 +00:00
import { VideoEditType } from './shared/video-edit.type'
import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
2020-06-23 12:10:17 +00:00
import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
import { VideoUploadComponent } from './video-add-components/video-upload.component'
2016-04-14 20:07:46 +00:00
2016-03-14 12:50:19 +00:00
@Component ( {
selector : 'my-videos-add' ,
2017-12-07 15:32:06 +00:00
templateUrl : './video-add.component.html' ,
2018-08-02 13:34:09 +00:00
styleUrls : [ './video-add.component.scss' ]
2016-03-14 12:50:19 +00:00
} )
2019-12-18 14:31:54 +00:00
export class VideoAddComponent implements OnInit , CanComponentDeactivate {
2020-02-07 09:00:34 +00:00
@ViewChild ( 'videoUpload' ) videoUpload : VideoUploadComponent
@ViewChild ( 'videoImportUrl' ) videoImportUrl : VideoImportUrlComponent
@ViewChild ( 'videoImportTorrent' ) videoImportTorrent : VideoImportTorrentComponent
2020-09-17 07:20:52 +00:00
@ViewChild ( 'videoGoLive' ) videoGoLive : VideoGoLiveComponent
2017-09-14 15:06:31 +00:00
2020-07-28 13:18:38 +00:00
user : AuthUser = null
2020-07-24 06:53:25 +00:00
2020-09-17 07:20:52 +00:00
secondStepType : VideoEditType
2018-08-02 13:34:09 +00:00
videoName : string
2021-05-11 13:03:30 +00:00
activeNav : string
2021-08-25 09:38:10 +00:00
uploadMessages : {
noQuota : string
autoBlock : string
quotaLeftDaily : string
quotaLeft : string
}
2021-08-26 06:40:18 +00:00
hasNoQuotaLeft = false
hasNoQuotaLeftDaily = false
2021-10-08 09:26:17 +00:00
serverConfig : HTMLServerConfig
2018-06-15 14:52:15 +00:00
2018-08-03 09:10:31 +00:00
constructor (
2019-12-10 09:02:23 +00:00
private auth : AuthService ,
2021-08-26 06:40:18 +00:00
private userService : UserService ,
2021-08-25 09:38:10 +00:00
private hooks : HooksService ,
2021-05-11 13:03:30 +00:00
private serverService : ServerService ,
private route : ActivatedRoute ,
private router : Router
2018-08-03 09:10:31 +00:00
) { }
2021-08-25 09:38:10 +00:00
get isContactFormEnabled ( ) {
return this . serverConfig . email . enabled && this . serverConfig . contactForm . enabled
}
2020-07-24 06:53:25 +00:00
get userInformationLoaded ( ) {
return this . auth . userInformationLoaded
}
2019-12-18 14:31:54 +00:00
ngOnInit ( ) {
2020-07-24 06:53:25 +00:00
this . user = this . auth . getUser ( )
2021-06-04 11:31:41 +00:00
this . serverConfig = this . serverService . getHTMLConfig ( )
2020-07-28 13:18:38 +00:00
2021-05-11 13:03:30 +00:00
if ( this . route . snapshot . fragment ) {
this . onNavChange ( this . route . snapshot . fragment )
}
2021-08-25 09:38:10 +00:00
this . buildUploadMessages ( )
2021-08-26 06:40:18 +00:00
this . userService . getMyVideoQuotaUsed ( )
. subscribe ( data = > {
// videoQuota left lower than 10%
if ( data . videoQuotaUsed > this . user . videoQuota * 0.9 ) {
this . hasNoQuotaLeft = true
}
// unlimited videoQuota
if ( this . user . videoQuota === - 1 ) {
this . hasNoQuotaLeft = false
}
// videoQuotaDaily left lower than 10%
if ( data . videoQuotaUsedDaily > this . user . videoQuotaDaily * 0.9 ) {
this . hasNoQuotaLeftDaily = true
}
// unlimited videoQuotaDaily
if ( this . user . videoQuotaDaily === - 1 ) {
this . hasNoQuotaLeftDaily = false
}
} )
2021-08-25 09:38:10 +00:00
}
private async buildUploadMessages ( ) {
// eslint-disable-next-line max-len
const noQuota = $localize ` Sorry, the upload feature is disabled for your account. If you want to add videos, an admin must unlock your quota. `
// eslint-disable-next-line max-len
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. `
// eslint-disable-next-line max-len
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. `
// eslint-disable-next-line max-len
const quotaLeft = $localize ` Your video quota is insufficient. If you want to add more videos, an admin must increase your quota. `
const uploadMessages = {
noQuota ,
autoBlock ,
quotaLeftDaily ,
quotaLeft
}
2021-08-25 09:41:10 +00:00
this . uploadMessages = await this . hooks . wrapObject ( uploadMessages , 'common' , 'filter:upload.messages.create.result' )
2021-05-11 13:03:30 +00:00
}
onNavChange ( newActiveNav : string ) {
this . activeNav = newActiveNav
this . router . navigate ( [ ] , { fragment : this.activeNav } )
2019-12-18 14:31:54 +00:00
}
2020-09-17 07:20:52 +00:00
onFirstStepDone ( type : VideoEditType , videoName : string ) {
2018-08-02 13:34:09 +00:00
this . secondStepType = type
this . videoName = videoName
2018-01-25 18:01:13 +00:00
}
2018-11-16 09:05:25 +00:00
onError ( ) {
this . videoName = undefined
this . secondStepType = undefined
}
2019-01-14 13:55:43 +00:00
@HostListener ( 'window:beforeunload' , [ '$event' ] )
onUnload ( event : any ) {
const { text , canDeactivate } = this . canDeactivate ( )
if ( canDeactivate ) return
event . returnValue = text
return text
}
canDeactivate ( ) : { canDeactivate : boolean , text? : string } {
2021-10-12 08:53:26 +00:00
if ( this . secondStepType === 'upload' ) return this . videoUpload . canDeactivate ( )
2018-08-06 13:18:35 +00:00
if ( this . secondStepType === 'import-url' ) return this . videoImportUrl . canDeactivate ( )
2018-08-06 15:13:39 +00:00
if ( this . secondStepType === 'import-torrent' ) return this . videoImportTorrent . canDeactivate ( )
2020-09-17 07:20:52 +00:00
if ( this . secondStepType === 'go-live' ) return this . videoGoLive . canDeactivate ( )
2018-07-12 17:02:00 +00:00
2018-08-02 13:34:09 +00:00
return { canDeactivate : true }
2017-12-07 15:32:06 +00:00
}
2018-08-03 09:10:31 +00:00
2018-08-06 15:13:39 +00:00
isVideoImportHttpEnabled ( ) {
2019-12-18 14:31:54 +00:00
return this . serverConfig . import . videos . http . enabled
2018-08-06 15:13:39 +00:00
}
isVideoImportTorrentEnabled ( ) {
2019-12-18 14:31:54 +00:00
return this . serverConfig . import . videos . torrent . enabled
2018-08-03 09:10:31 +00:00
}
2019-12-10 09:02:23 +00:00
2020-09-17 07:20:52 +00:00
isVideoLiveEnabled ( ) {
return this . serverConfig . live . enabled
}
2019-12-10 09:02:23 +00:00
isInSecondStep ( ) {
return ! ! this . secondStepType
}
isRootUser ( ) {
2020-07-28 13:18:38 +00:00
return this . user . username === 'root'
2019-12-10 09:02:23 +00:00
}
2016-03-14 12:50:19 +00:00
}