]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/files-cache/videos-torrent-cache.ts
Force live stream termination
[github/Chocobozzz/PeerTube.git] / server / lib / files-cache / videos-torrent-cache.ts
index 23217f1403119acfdb1f5b943c51f73260eb0fd4..a6bf98dd48daaa8b5a12faad5dac088591a55dd0 100644 (file)
@@ -1,11 +1,12 @@
 import { join } from 'path'
+import { logger } from '@server/helpers/logger'
 import { doRequestAndSaveToFile } from '@server/helpers/requests'
 import { VideoFileModel } from '@server/models/video/video-file'
+import { MVideo, MVideoFile } from '@server/types/models'
 import { CONFIG } from '../../initializers/config'
 import { FILES_CACHE } from '../../initializers/constants'
 import { VideoModel } from '../../models/video/video'
 import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
-import { MVideo, MVideoFile } from '@server/types/models'
 
 class VideosTorrentCache extends AbstractVideoStaticFileCache <string> {
 
@@ -40,17 +41,23 @@ class VideosTorrentCache extends AbstractVideoStaticFileCache <string> {
     if (file.getVideo().isOwned()) throw new Error('Cannot load remote file of owned video.')
 
     // Used to fetch the path
-    const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(file.getVideo().id)
+    const video = await VideoModel.loadFull(file.getVideo().id)
     if (!video) return undefined
 
     const remoteUrl = file.getRemoteTorrentUrl(video)
     const destPath = join(FILES_CACHE.TORRENTS.DIRECTORY, file.torrentFilename)
 
-    await doRequestAndSaveToFile(remoteUrl, destPath)
+    try {
+      await doRequestAndSaveToFile(remoteUrl, destPath)
 
-    const downloadName = this.buildDownloadName(video, file)
+      const downloadName = this.buildDownloadName(video, file)
 
-    return { isOwned: false, path: destPath, downloadName }
+      return { isOwned: false, path: destPath, downloadName }
+    } catch (err) {
+      logger.info('Cannot fetch remote torrent file %s.', remoteUrl, { err })
+
+      return undefined
+    }
   }
 
   private buildDownloadName (video: MVideo, file: MVideoFile) {