]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/webtorrent.ts
Introduce debug command
[github/Chocobozzz/PeerTube.git] / server / helpers / webtorrent.ts
index 73418aa0a903b42a2bb5b8b1e80255c209a17178..d8220ba9c6583e3acb13e8ec7de8ba306a8fd983 100644 (file)
@@ -7,13 +7,14 @@ import * as WebTorrent from 'webtorrent'
 import { isArray } from '@server/helpers/custom-validators/misc'
 import { WEBSERVER } from '@server/initializers/constants'
 import { generateTorrentFileName, getVideoFilePath } from '@server/lib/video-paths'
-import { MVideo, MVideoWithHost } from '@server/types/models/video/video'
+import { MVideo } from '@server/types/models/video/video'
 import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file'
 import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist'
 import { CONFIG } from '../initializers/config'
 import { promisify2 } from './core-utils'
 import { logger } from './logger'
 import { generateVideoImportTmpPath } from './utils'
+import { extractVideo } from './video'
 
 const createTorrentPromise = promisify2<string, any, any>(createTorrent)
 
@@ -77,12 +78,12 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
   })
 }
 
-// FIXME: refactor/merge videoOrPlaylist and video arguments
 async function createTorrentAndSetInfoHash (
   videoOrPlaylist: MVideo | MStreamingPlaylistVideo,
-  video: MVideoWithHost,
   videoFile: MVideoFile
 ) {
+  const video = extractVideo(videoOrPlaylist)
+
   const options = {
     // Keep the extname, it's used by the client to stream the file inside a web browser
     name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`,
@@ -107,16 +108,13 @@ async function createTorrentAndSetInfoHash (
   videoFile.torrentFilename = torrentFilename
 }
 
-// FIXME: merge/refactor videoOrPlaylist and video arguments
 function generateMagnetUri (
-  videoOrPlaylist: MVideo | MStreamingPlaylistVideo,
-  video: MVideoWithHost,
+  video: MVideo,
   videoFile: MVideoFileRedundanciesOpt,
-  baseUrlHttp: string,
-  baseUrlWs: string
+  trackerUrls: string[]
 ) {
   const xs = videoFile.getTorrentUrl()
-  const announce = videoOrPlaylist.getTrackerUrls(baseUrlHttp, baseUrlWs)
+  const announce = trackerUrls
   let urlList = [ videoFile.getFileUrl(video) ]
 
   const redundancies = videoFile.RedundancyVideos