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'
|
2020-07-28 13:18:38 +00:00
|
|
|
import { AuthService, AuthUser, CanComponentDeactivate, ServerService } 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-06-04 11:31:41 +00:00
|
|
|
private 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-05-11 13:03:30 +00:00
|
|
|
private serverService: ServerService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router
|
2018-08-03 09:10:31 +00:00
|
|
|
) {}
|
|
|
|
|
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
|
|
|
|
|
|
|
this.user = this.auth.getUser()
|
2021-05-11 13:03:30 +00:00
|
|
|
|
|
|
|
if (this.route.snapshot.fragment) {
|
|
|
|
this.onNavChange(this.route.snapshot.fragment)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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} {
|
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
|
|
|
}
|