From d61893f7236abbed30c25b1823e6ecad93a8e8dd Mon Sep 17 00:00:00 2001
From: Chocobozzz <me@florianbigard.com>
Date: Thu, 25 Feb 2021 13:56:07 +0100
Subject: Async torrent creation

---
 server/models/video/video-file.ts         | 8 ++++++++
 server/models/video/video-format-utils.ts | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

(limited to 'server/models')

diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index 4df2c20bc..1ad796104 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -457,18 +457,26 @@ export class VideoFileModel extends Model {
 
   // We proxify torrent requests so use a local URL
   getTorrentUrl () {
+    if (!this.torrentFilename) return null
+
     return WEBSERVER.URL + this.getTorrentStaticPath()
   }
 
   getTorrentStaticPath () {
+    if (!this.torrentFilename) return null
+
     return join(LAZY_STATIC_PATHS.TORRENTS, this.torrentFilename)
   }
 
   getTorrentDownloadUrl () {
+    if (!this.torrentFilename) return null
+
     return WEBSERVER.URL + join(STATIC_DOWNLOAD_PATHS.TORRENTS, this.torrentFilename)
   }
 
   removeTorrent () {
+    if (!this.torrentFilename) return null
+
     const torrentPath = getTorrentFilePath(this)
     return remove(torrentPath)
       .catch(err => logger.warn('Cannot delete torrent %s.', torrentPath, { err }))
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index a6a1a4f0d..bcba90093 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
+        magnetUri: includeMagnet && videoFile.torrentFilename
           ? generateMagnetUri(video, videoFile, trackerUrls)
           : undefined,
 
-- 
cgit v1.2.3