2019-12-18 14:31:54 +00:00
|
|
|
import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
|
2018-01-25 18:01:13 +00:00
|
|
|
import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
|
2018-08-06 13:30:24 +00:00
|
|
|
import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component'
|
|
|
|
import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component'
|
2019-12-10 09:02:23 +00:00
|
|
|
import { AuthService, ServerService } from '@app/core'
|
2018-08-06 15:13:39 +00:00
|
|
|
import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component'
|
2019-12-18 14:31:54 +00:00
|
|
|
import { ServerConfig } from '@shared/models'
|
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 {
|
2019-07-24 14:05:59 +00:00
|
|
|
@ViewChild('videoUpload', { static: false }) videoUpload: VideoUploadComponent
|
|
|
|
@ViewChild('videoImportUrl', { static: false }) videoImportUrl: VideoImportUrlComponent
|
|
|
|
@ViewChild('videoImportTorrent', { static: false }) videoImportTorrent: VideoImportTorrentComponent
|
2017-09-14 15:06:31 +00:00
|
|
|
|
2018-08-06 15:13:39 +00:00
|
|
|
secondStepType: 'upload' | 'import-url' | 'import-torrent'
|
2018-08-02 13:34:09 +00:00
|
|
|
videoName: string
|
2019-12-18 14:31:54 +00:00
|
|
|
serverConfig: ServerConfig
|
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,
|
2018-08-03 09:10:31 +00:00
|
|
|
private serverService: ServerService
|
|
|
|
) {}
|
|
|
|
|
2019-12-18 14:31:54 +00:00
|
|
|
ngOnInit () {
|
|
|
|
this.serverConfig = this.serverService.getTmpConfig()
|
|
|
|
|
|
|
|
this.serverService.getConfig()
|
|
|
|
.subscribe(config => this.serverConfig = config)
|
|
|
|
}
|
|
|
|
|
2018-08-06 15:13:39 +00:00
|
|
|
onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', 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-02 13:34:09 +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()
|
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
|
|
|
|
|
|
|
isInSecondStep () {
|
|
|
|
return !!this.secondStepType
|
|
|
|
}
|
|
|
|
|
|
|
|
isRootUser () {
|
|
|
|
return this.auth.getUser().username === 'root'
|
|
|
|
}
|
2016-03-14 12:50:19 +00:00
|
|
|
}
|