Disable webtorrent support in client
[oweals/peertube.git] / client / src / app / shared / video / modals / video-download.component.ts
1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { VideoDetails } from '../../../shared/video/video-details.model'
3 import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { Notifier } from '@app/core'
6
7 @Component({
8   selector: 'my-video-download',
9   templateUrl: './video-download.component.html',
10   styleUrls: [ './video-download.component.scss' ]
11 })
12 export class VideoDownloadComponent {
13   @ViewChild('modal', { static: true }) modal: ElementRef
14
15   downloadType: 'direct' | 'torrent' = 'torrent'
16   resolutionId: number | string = -1
17
18   video: VideoDetails
19   activeModal: NgbActiveModal
20
21   constructor (
22     private notifier: Notifier,
23     private modalService: NgbModal,
24     private i18n: I18n
25   ) { }
26
27   getVideoFiles () {
28     if (!this.video) return []
29
30     return this.video.getFiles()
31   }
32
33   show (video: VideoDetails) {
34     this.video = video
35
36     this.activeModal = this.modalService.open(this.modal)
37
38     this.resolutionId = this.getVideoFiles()[0].resolution.id
39   }
40
41   onClose () {
42     this.video = undefined
43   }
44
45   download () {
46     window.location.assign(this.getLink())
47     this.activeModal.close()
48   }
49
50   getLink () {
51     // HTML select send us a string, so convert it to a number
52     this.resolutionId = parseInt(this.resolutionId.toString(), 10)
53
54     const file = this.getVideoFiles().find(f => f.resolution.id === this.resolutionId)
55     if (!file) {
56       console.error('Could not find file with resolution %d.', this.resolutionId)
57       return
58     }
59
60     switch (this.downloadType) {
61       case 'direct':
62         return file.fileDownloadUrl
63
64       case 'torrent':
65         return file.torrentDownloadUrl
66     }
67   }
68
69   activateCopiedMessage () {
70     this.notifier.success(this.i18n('Copied'))
71   }
72 }