]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/video-download.component.ts
Better admin tables
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / video-download.component.ts
index 095df16989f4eaa57da851f7c97e2a484fd16a24..44ece986cfce96ecb95ddcd7c0a2dc400edec681 100644 (file)
@@ -1,4 +1,4 @@
-import { Component, Input, ViewChild } from '@angular/core'
+import { Component, Input, OnInit, ViewChild } from '@angular/core'
 import { ModalDirective } from 'ngx-bootstrap/modal'
 import { VideoDetails } from '../../shared/video/video-details.model'
 
@@ -7,15 +7,22 @@ import { VideoDetails } from '../../shared/video/video-details.model'
   templateUrl: './video-download.component.html',
   styleUrls: [ './video-download.component.scss' ]
 })
-export class VideoDownloadComponent {
+export class VideoDownloadComponent implements OnInit {
   @Input() video: VideoDetails = null
 
   @ViewChild('modal') modal: ModalDirective
 
+  downloadType: 'direct' | 'torrent' = 'torrent'
+  resolution = -1
+
   constructor () {
     // empty
   }
 
+  ngOnInit () {
+    this.resolution = this.video.files[0].resolution
+  }
+
   show () {
     this.modal.show()
   }
@@ -23,4 +30,15 @@ export class VideoDownloadComponent {
   hide () {
     this.modal.hide()
   }
+
+  download () {
+    const file = this.video.files.find(f => f.resolution === this.resolution)
+    if (!file) {
+      console.error('Could not find file with resolution %d.', this.resolution)
+      return
+    }
+
+    const link = this.downloadType === 'direct' ? file.fileUrl : file.torrentUrl
+    window.open(link)
+  }
 }