]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Avoid error when file has no torrent file
authorChocobozzz <me@florianbigard.com>
Tue, 25 May 2021 09:30:00 +0000 (11:30 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 25 May 2021 09:35:29 +0000 (11:35 +0200)
server/models/video/video-file.ts
server/models/video/video-format-utils.ts

index e3fa2f3d255cb3a4f5695a7118904ba3cdd00c86..22cf638046afb6e3fb1ee0bf2e33285cc5484859 100644 (file)
@@ -402,6 +402,10 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
     return VideoFileModel.destroy(options)
   }
 
+  hasTorrent () {
+    return this.infoHash && this.torrentFilename
+  }
+
   getVideoOrStreamingPlaylist (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo | MStreamingPlaylistVideo {
     if (this.videoId) return (this as MVideoFileVideo).Video
 
index bcba90093d39a50fe89ebab0d2645ac2eaa2075e..551cb2842aa6883ae69f02506c802c843b63e9ec 100644 (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
-    })
-
-    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
+      })
+    }
   }
 }