Avoid error when file has no torrent file

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

View File

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

View File

@ -205,7 +205,7 @@ function videoFilesModelToFormattedJSON (
label: videoFile.resolution + 'p' label: videoFile.resolution + 'p'
}, },
magnetUri: includeMagnet && videoFile.torrentFilename magnetUri: includeMagnet && videoFile.hasTorrent()
? generateMagnetUri(video, videoFile, trackerUrls) ? generateMagnetUri(video, videoFile, trackerUrls)
: undefined, : undefined,
@ -253,6 +253,7 @@ function addVideoFilesInAPAcc (
fps: file.fps fps: file.fps
}) })
if (file.hasTorrent()) {
acc.push({ acc.push({
type: 'Link', type: 'Link',
mediaType: 'application/x-bittorrent' as 'application/x-bittorrent', mediaType: 'application/x-bittorrent' as 'application/x-bittorrent',
@ -268,6 +269,7 @@ function addVideoFilesInAPAcc (
}) })
} }
} }
}
function videoModelToActivityPubObject (video: MVideoAP): VideoObject { function videoModelToActivityPubObject (video: MVideoAP): VideoObject {
if (!video.Tags) video.Tags = [] if (!video.Tags) video.Tags = []