-import { Component, Input, OnInit, ViewChild } from '@angular/core'
-import { ModalDirective } from 'ngx-bootstrap/modal'
+import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'
import { VideoDetails } from '../../../shared/video/video-details.model'
+import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
@Component({
selector: 'my-video-download',
export class VideoDownloadComponent implements OnInit {
@Input() video: VideoDetails = null
- @ViewChild('modal') modal: ModalDirective
+ @ViewChild('modal') modal: ElementRef
- downloadType: 'direct' | 'torrent' = 'torrent'
+ downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
resolutionId: number | string = -1
- constructor () {
- // empty
- }
+ constructor (private modalService: NgbModal) { }
ngOnInit () {
this.resolutionId = this.video.files[0].resolution.id
}
show () {
- this.modal.show()
- }
-
- hide () {
- this.modal.hide()
+ this.modalService.open(this.modal)
}
download () {
return
}
- const link = this.downloadType === 'direct' ? file.fileDownloadUrl : file.torrentDownloadUrl
+ const link = (() => {
+ switch (this.downloadType) {
+ case 'direct': {
+ return file.fileDownloadUrl
+ }
+ case 'torrent': {
+ return file.torrentDownloadUrl
+ }
+ case 'magnet': {
+ return file.magnetUri
+ }
+ }
+ })()
window.location.assign(link)
}
}