1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2 import { AuthService, CanComponentDeactivate, ServerService } from '@app/core'
3 import { ServerConfig } from '@shared/models'
4 import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
5 import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
6 import { VideoUploadComponent } from './video-add-components/video-upload.component'
9 selector: 'my-videos-add',
10 templateUrl: './video-add.component.html',
11 styleUrls: [ './video-add.component.scss' ]
13 export class VideoAddComponent implements OnInit, CanComponentDeactivate {
14 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
18 secondStepType: 'upload' | 'import-url' | 'import-torrent'
20 serverConfig: ServerConfig
23 private auth: AuthService,
24 private serverService: ServerService
28 this.serverConfig = this.serverService.getTmpConfig()
30 this.serverService.getConfig()
31 .subscribe(config => this.serverConfig = config)
34 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
35 this.secondStepType = type
36 this.videoName = videoName
40 this.videoName = undefined
41 this.secondStepType = undefined
44 @HostListener('window:beforeunload', [ '$event' ])
45 onUnload (event: any) {
46 const { text, canDeactivate } = this.canDeactivate()
48 if (canDeactivate) return
50 event.returnValue = text
54 canDeactivate (): { canDeactivate: boolean, text?: string} {
55 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
56 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
57 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
59 return { canDeactivate: true }
62 isVideoImportHttpEnabled () {
63 return this.serverConfig.import.videos.http.enabled
66 isVideoImportTorrentEnabled () {
67 return this.serverConfig.import.videos.torrent.enabled
71 return !!this.secondStepType
75 return this.auth.getUser().username === 'root'