]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/videos/+video-watch/modal/video-download.component.ts
Improve frontend accessibility
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-download.component.ts
... / ...
CommitLineData
1import { Component, Input, OnInit, ViewChild } from '@angular/core'
2import { ModalDirective } from 'ngx-bootstrap/modal'
3import { VideoDetails } from '../../../shared/video/video-details.model'
4
5@Component({
6 selector: 'my-video-download',
7 templateUrl: './video-download.component.html',
8 styleUrls: [ './video-download.component.scss' ]
9})
10export class VideoDownloadComponent implements OnInit {
11 @Input() video: VideoDetails = null
12
13 @ViewChild('modal') modal: ModalDirective
14
15 downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
16 resolutionId: number | string = -1
17
18 constructor () {
19 // empty
20 }
21
22 ngOnInit () {
23 this.resolutionId = this.video.files[0].resolution.id
24 }
25
26 show () {
27 this.modal.show()
28 }
29
30 hide () {
31 this.modal.hide()
32 }
33
34 download () {
35 // HTML select send us a string, so convert it to a number
36 this.resolutionId = parseInt(this.resolutionId.toString(), 10)
37
38 const file = this.video.files.find(f => f.resolution.id === this.resolutionId)
39 if (!file) {
40 console.error('Could not find file with resolution %d.', this.resolutionId)
41 return
42 }
43
44 const link = (() => {
45 switch (this.downloadType) {
46 case 'direct': {
47 return file.fileDownloadUrl
48 }
49 case 'torrent': {
50 return file.torrentDownloadUrl
51 }
52 case 'magnet': {
53 return file.magnetUri
54 }
55 }
56 })()
57 window.location.assign(link)
58 }
59}