]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/modal/video-download.component.ts
Update client according to new model paths
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-download.component.ts
CommitLineData
63347a0f 1import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'
4635f59d 2import { VideoDetails } from '../../../shared/video/video-details.model'
63347a0f 3import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
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
63347a0f 13 @ViewChild('modal') modal: ElementRef
cf02fbfb 14
5511da62 15 downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
09700934 16 resolutionId: number | string = -1
5f0805d3 17
63347a0f 18 constructor (private modalService: NgbModal) {
cf02fbfb
C
19 // empty
20 }
21
5f0805d3 22 ngOnInit () {
09700934 23 this.resolutionId = this.video.files[0].resolution.id
5f0805d3
C
24 }
25
df98563e 26 show () {
63347a0f 27 this.modalService.open(this.modal)
cf02fbfb 28 }
5f0805d3
C
29
30 download () {
00336945 31 // HTML select send us a string, so convert it to a number
09700934 32 this.resolutionId = parseInt(this.resolutionId.toString(), 10)
00336945 33
09700934 34 const file = this.video.files.find(f => f.resolution.id === this.resolutionId)
5f0805d3 35 if (!file) {
09700934 36 console.error('Could not find file with resolution %d.', this.resolutionId)
5f0805d3
C
37 return
38 }
39
5511da62
RK
40 const link = (() => {
41 switch (this.downloadType) {
42 case 'direct': {
43 return file.fileDownloadUrl
44 }
45 case 'torrent': {
46 return file.torrentDownloadUrl
47 }
48 case 'magnet': {
49 return file.magnetUri
50 }
51 }
52 })()
02756fbd 53 window.location.assign(link)
5f0805d3 54 }
cf02fbfb 55}