aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-25 11:30:00 +0200
committerChocobozzz <me@florianbigard.com>2021-05-25 11:35:29 +0200
commitc4d125527a433db9ba536bf3bb8ef19569a85a73 (patch)
treea05d388e047d3088eb037489919b64dd497981ac
parent3dc8a86c80a6d2fbcf4c7c02a31c1c60c8e6b598 (diff)
downloadPeerTube-c4d125527a433db9ba536bf3bb8ef19569a85a73.tar.gz
PeerTube-c4d125527a433db9ba536bf3bb8ef19569a85a73.tar.zst
PeerTube-c4d125527a433db9ba536bf3bb8ef19569a85a73.zip
Avoid error when file has no torrent file
-rw-r--r--server/models/video/video-file.ts4
-rw-r--r--server/models/video/video-format-utils.ts30
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<Partial<AttributesOnly<VideoFileModel>
402 return VideoFileModel.destroy(options) 402 return VideoFileModel.destroy(options)
403 } 403 }
404 404
405 hasTorrent () {
406 return this.infoHash && this.torrentFilename
407 }
408
405 getVideoOrStreamingPlaylist (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo | MStreamingPlaylistVideo { 409 getVideoOrStreamingPlaylist (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo | MStreamingPlaylistVideo {
406 if (this.videoId) return (this as MVideoFileVideo).Video 410 if (this.videoId) return (this as MVideoFileVideo).Video
407 411
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 (
205 label: videoFile.resolution + 'p' 205 label: videoFile.resolution + 'p'
206 }, 206 },
207 207
208 magnetUri: includeMagnet && videoFile.torrentFilename 208 magnetUri: includeMagnet && videoFile.hasTorrent()
209 ? generateMagnetUri(video, videoFile, trackerUrls) 209 ? generateMagnetUri(video, videoFile, trackerUrls)
210 : undefined, 210 : undefined,
211 211
@@ -253,19 +253,21 @@ function addVideoFilesInAPAcc (
253 fps: file.fps 253 fps: file.fps
254 }) 254 })
255 255
256 acc.push({ 256 if (file.hasTorrent()) {
257 type: 'Link', 257 acc.push({
258 mediaType: 'application/x-bittorrent' as 'application/x-bittorrent', 258 type: 'Link',
259 href: file.getTorrentUrl(), 259 mediaType: 'application/x-bittorrent' as 'application/x-bittorrent',
260 height: file.resolution 260 href: file.getTorrentUrl(),
261 }) 261 height: file.resolution
262 262 })
263 acc.push({ 263
264 type: 'Link', 264 acc.push({
265 mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet', 265 type: 'Link',
266 href: generateMagnetUri(video, file, trackerUrls), 266 mediaType: 'application/x-bittorrent;x-scheme-handler/magnet' as 'application/x-bittorrent;x-scheme-handler/magnet',
267 height: file.resolution 267 href: generateMagnetUri(video, file, trackerUrls),
268 }) 268 height: file.resolution
269 })
270 }
269 } 271 }
270} 272}
271 273