diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-25 11:30:00 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-25 11:34:43 +0200 |
commit | be89e66895948bb52b3f10186bcea1a8b92ef912 (patch) | |
tree | 47a4f5df534820b983df6d07fb76cf384ea197f2 /server/models | |
parent | 6a3391bcede8e7a2bec83963221c112e6752b1a8 (diff) | |
download | PeerTube-be89e66895948bb52b3f10186bcea1a8b92ef912.tar.gz PeerTube-be89e66895948bb52b3f10186bcea1a8b92ef912.tar.zst PeerTube-be89e66895948bb52b3f10186bcea1a8b92ef912.zip |
Avoid error when file has no torrent file
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-file.ts | 4 | ||||
-rw-r--r-- | 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 1ad796104..0b5946149 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -401,6 +401,10 @@ export class VideoFileModel extends Model { | |||
401 | return VideoFileModel.destroy(options) | 401 | return VideoFileModel.destroy(options) |
402 | } | 402 | } |
403 | 403 | ||
404 | hasTorrent () { | ||
405 | return this.infoHash && this.torrentFilename | ||
406 | } | ||
407 | |||
404 | getVideoOrStreamingPlaylist (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo | MStreamingPlaylistVideo { | 408 | getVideoOrStreamingPlaylist (this: MVideoFileVideo | MVideoFileStreamingPlaylistVideo): MVideo | MStreamingPlaylistVideo { |
405 | if (this.videoId) return (this as MVideoFileVideo).Video | 409 | if (this.videoId) return (this as MVideoFileVideo).Video |
406 | 410 | ||
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 | ||