]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/modal/video-download.component.ts
Fix title and action buttons in video watch
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-download.component.ts
CommitLineData
5f0805d3 1import { Component, Input, OnInit, ViewChild } from '@angular/core'
df98563e 2import { ModalDirective } from 'ngx-bootstrap/modal'
4635f59d 3import { VideoDetails } from '../../../shared/video/video-details.model'
cf02fbfb
C
4
5@Component({
a96aed15
C
6 selector: 'my-video-download',
7 templateUrl: './video-download.component.html',
0727cab0 8 styleUrls: [ './video-download.component.scss' ]
cf02fbfb 9})
5f0805d3 10export class VideoDownloadComponent implements OnInit {
404b54e1 11 @Input() video: VideoDetails = null
cf02fbfb 12
df98563e 13 @ViewChild('modal') modal: ModalDirective
cf02fbfb 14
5f0805d3
C
15 downloadType: 'direct' | 'torrent' = 'torrent'
16 resolution = -1
17
df98563e 18 constructor () {
cf02fbfb
C
19 // empty
20 }
21
5f0805d3
C
22 ngOnInit () {
23 this.resolution = this.video.files[0].resolution
24 }
25
df98563e
C
26 show () {
27 this.modal.show()
cf02fbfb
C
28 }
29
df98563e
C
30 hide () {
31 this.modal.hide()
cf02fbfb 32 }
5f0805d3
C
33
34 download () {
35 const file = this.video.files.find(f => f.resolution === this.resolution)
36 if (!file) {
37 console.error('Could not find file with resolution %d.', this.resolution)
38 return
39 }
40
41 const link = this.downloadType === 'direct' ? file.fileUrl : file.torrentUrl
42 window.open(link)
43 }
cf02fbfb 44}