From c4d125527a433db9ba536bf3bb8ef19569a85a73 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 25 May 2021 11:30:00 +0200 Subject: [PATCH] Avoid error when file has no torrent file --- server/models/video/video-file.ts | 4 +++ server/models/video/video-format-utils.ts | 30 ++++++++++++----------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index e3fa2f3d2..22cf63804 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts @@ -402,6 +402,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 diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts index bcba90093..551cb2842 100644 --- a/server/models/video/video-format-utils.ts +++ b/server/models/video/video-format-utils.ts @@ -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 - }) - - 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 - }) + 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 + }) + } } } -- 2.41.0