]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add.component.ts
Switch examples to curl since httpie has a 512MB limit (#3012)
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
CommitLineData
ba430d75 1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2e7f2627 2import { AuthService, CanComponentDeactivate, ServerService, User } from '@app/core'
ba430d75 3import { ServerConfig } from '@shared/models'
67ed6552
C
4import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
5import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
6import { VideoUploadComponent } from './video-add-components/video-upload.component'
1553e15d 7
dc8bc31b
C
8@Component({
9 selector: 'my-videos-add',
27e1a06c 10 templateUrl: './video-add.component.html',
fbad87b0 11 styleUrls: [ './video-add.component.scss' ]
dc8bc31b 12})
ba430d75 13export class VideoAddComponent implements OnInit, CanComponentDeactivate {
2f5d2ec5
C
14 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
bfb3a98f 17
2e7f2627
K
18 user: User = null
19
ce33919c 20 secondStepType: 'upload' | 'import-url' | 'import-torrent'
fbad87b0 21 videoName: string
ba430d75 22 serverConfig: ServerConfig
bbe0f064 23
5d08a6a7 24 constructor (
cd3d847d 25 private auth: AuthService,
5d08a6a7
C
26 private serverService: ServerService
27 ) {}
28
2e7f2627
K
29 get userInformationLoaded () {
30 return this.auth.userInformationLoaded
31 }
32
ba430d75 33 ngOnInit () {
2e7f2627
K
34 this.user = this.auth.getUser()
35
ba430d75
C
36 this.serverConfig = this.serverService.getTmpConfig()
37
38 this.serverService.getConfig()
39 .subscribe(config => this.serverConfig = config)
40 }
41
ce33919c 42 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
fbad87b0
C
43 this.secondStepType = type
44 this.videoName = videoName
f6a043df
C
45 }
46
7373507f
C
47 onError () {
48 this.videoName = undefined
49 this.secondStepType = undefined
50 }
51
674a66bb
C
52 @HostListener('window:beforeunload', [ '$event' ])
53 onUnload (event: any) {
54 const { text, canDeactivate } = this.canDeactivate()
55
56 if (canDeactivate) return
57
58 event.returnValue = text
59 return text
60 }
61
62 canDeactivate (): { canDeactivate: boolean, text?: string} {
fbad87b0 63 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
047559af 64 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 65 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
40e87e9e 66
fbad87b0 67 return { canDeactivate: true }
27e1a06c 68 }
5d08a6a7 69
ce33919c 70 isVideoImportHttpEnabled () {
ba430d75 71 return this.serverConfig.import.videos.http.enabled
ce33919c
C
72 }
73
74 isVideoImportTorrentEnabled () {
ba430d75 75 return this.serverConfig.import.videos.torrent.enabled
5d08a6a7 76 }
cd3d847d
C
77
78 isInSecondStep () {
79 return !!this.secondStepType
80 }
81
82 isRootUser () {
83 return this.auth.getUser().username === 'root'
84 }
dc8bc31b 85}