Fix #639 providing magnet URI in player and download modal

This commit is contained in:
Rigel Kent 2018-06-22 16:29:01 +02:00 committed by Chocobozzz
parent 92d83c6a78
commit 5511da6289
3 changed files with 26 additions and 2 deletions

View File

@ -24,6 +24,11 @@
<input type="radio" name="download" id="download-direct" [(ngModel)]="downloadType" value="direct"> <input type="radio" name="download" id="download-direct" [(ngModel)]="downloadType" value="direct">
<label i18n for="download-direct">Direct download</label> <label i18n for="download-direct">Direct download</label>
</div> </div>
<div class="peertube-radio-container">
<input type="radio" name="download" id="download-magnet" [(ngModel)]="downloadType" value="magnet">
<label i18n for="download-magnet">Torrent (magnet)</label>
</div>
</div> </div>
<div class="form-group inputs"> <div class="form-group inputs">

View File

@ -12,7 +12,7 @@ export class VideoDownloadComponent implements OnInit {
@ViewChild('modal') modal: ModalDirective @ViewChild('modal') modal: ModalDirective
downloadType: 'direct' | 'torrent' = 'torrent' downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
resolutionId: number | string = -1 resolutionId: number | string = -1
constructor () { constructor () {
@ -41,7 +41,19 @@ export class VideoDownloadComponent implements OnInit {
return 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) window.location.assign(link)
} }
} }

View File

@ -143,6 +143,13 @@ function addContextMenu (player: any, videoEmbedUrl: string) {
listener: () => { listener: () => {
copyToClipboard(buildVideoEmbed(videoEmbedUrl)) copyToClipboard(buildVideoEmbed(videoEmbedUrl))
} }
},
{
label: player.localize('Copy magnet URI'),
listener: function () {
const player = this
copyToClipboard(player.peertube().getCurrentVideoFile().magnetUri)
}
} }
] ]
}) })