Avoid error when file has no torrent file

pull/4048/head
Chocobozzz 2021-05-25 11:30:00 +02:00
parent 6a3391bced
commit be89e66895
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 19 additions and 13 deletions

View File

@ -401,6 +401,10 @@ export class VideoFileModel extends Model {
return VideoFileModel.destroy(options)
}
hasTorrent () {
return this.infoHash && this.torrentFilename
}
getVideoOrStreamingPlaylist (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo | MStreamingPlaylistVideo {
if (this.videoId) return (this as MVideoFileVideo).Video

View File

@ -205,7 +205,7 @@ function videoFilesModelToFormattedJSON (
label: videoFile.resolution + 'p'
},
magnetUri: includeMagnet && videoFile.torrentFilename
magnetUri: includeMagnet && videoFile.hasTorrent()
? generateMagnetUri(video, videoFile, trackerUrls)
: undefined,
@ -253,19 +253,21 @@ function addVideoFilesInAPAcc (
fps: file.fps
})
acc.push({
type: 'Link',
mediaType: 'application/x-bittorrent' as 'application/x-bittorrent',
href: file.getTorrentUrl(),
height: file.resolution
})
if (file.hasTorrent()) {
acc.push({
type: 'Link',
mediaType: 'application/x-bittorrent' as 'application/x-bittorrent',
href: file.getTorrentUrl(),
height: file.resolution
})
acc.push({
type: 'Link',
mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet',
href: generateMagnetUri(video, file, trackerUrls),
height: file.resolution
})
acc.push({
type: 'Link',
mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet',
href: generateMagnetUri(video, file, trackerUrls),
height: file.resolution
})
}
}
}