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