]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
More robust webtorrent redundancy download
authorChocobozzz <me@florianbigard.com>
Mon, 6 Sep 2021 07:29:25 +0000 (09:29 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 6 Sep 2021 14:19:49 +0000 (16:19 +0200)
Avoid issues with inconsistencies between magnet infohash and torrent
infohash, blocking webtorrent upload that will timeout

client/src/app/shared/shared-video-miniature/video-filters.model.ts
server/helpers/webtorrent.ts
server/lib/job-queue/handlers/video-import.ts
server/lib/schedulers/videos-redundancy-scheduler.ts
server/models/video/video-file.ts

index f5095b85b7204ff08cf15f50a3ca5cdfedef5d1c..920dc826c7018fd20555006b6e4f96b4f9607d0c 100644 (file)
@@ -74,8 +74,6 @@ export class VideoFilters {
   }
 
   setNSFWPolicy (nsfwPolicy: NSFWPolicyType) {
-    console.log(nsfwPolicy)
-
     this.updateDefaultNSFW(nsfwPolicy)
   }
 
index 83b46e08544f6250cabf255f098075f925fc866b..5e1ea61983c2197ff8ad59eeba01148ff645b819 100644 (file)
@@ -21,8 +21,8 @@ import { extractVideo } from './video'
 
 const createTorrentPromise = promisify2<string, any, any>(createTorrent)
 
-async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) {
-  const id = target.magnetUri || target.torrentName
+async function downloadWebTorrentVideo (target: { uri: string, torrentName?: string }, timeout: number) {
+  const id = target.uri || target.torrentName
   let timer
 
   const path = generateVideoImportTmpPath(id)
@@ -35,7 +35,7 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
     const webtorrent = new WebTorrent()
     let file: TorrentFile
 
-    const torrentId = target.magnetUri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName)
+    const torrentId = target.uri || join(CONFIG.STORAGE.TORRENTS_DIR, target.torrentName)
 
     const options = { path: directoryPath }
     const torrent = webtorrent.add(torrentId, options, torrent => {
index bdbf07a067977023d32cb2174baea56cfed9126e..8313c256180ec84e55781e6893bb4d72dc2f66c4 100644 (file)
@@ -63,7 +63,7 @@ async function processTorrentImport (job: Job, payload: VideoImportTorrentPayloa
   }
   const target = {
     torrentName: videoImport.torrentName ? getSecureTorrentName(videoImport.torrentName) : undefined,
-    magnetUri: videoImport.magnetUri
+    uri: videoImport.magnetUri
   }
   return processFile(() => downloadWebTorrentVideo(target, VIDEO_IMPORT_TIMEOUT), videoImport, options)
 }
index 633cbcf6c1f4c26e2a554c24ccf760a344d6e998..155d43343858bc131df063c680e4a3e827dffe1a 100644 (file)
@@ -1,7 +1,6 @@
 import { move } from 'fs-extra'
 import { join } from 'path'
 import { getServerActor } from '@server/models/application/application'
-import { TrackerModel } from '@server/models/server/tracker'
 import { VideoModel } from '@server/models/video/video'
 import {
   MStreamingPlaylistFiles,
@@ -15,7 +14,7 @@ import {
 } from '@server/types/models'
 import { VideosRedundancyStrategy } from '../../../shared/models/redundancy'
 import { logger, loggerTagsFactory } from '../../helpers/logger'
-import { downloadWebTorrentVideo, generateMagnetUri } from '../../helpers/webtorrent'
+import { downloadWebTorrentVideo } from '../../helpers/webtorrent'
 import { CONFIG } from '../../initializers/config'
 import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT } from '../../initializers/constants'
 import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
@@ -232,10 +231,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
 
     logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, strategy, lTags(video.uuid))
 
-    const trackerUrls = await TrackerModel.listUrlsByVideoId(video.id)
-    const magnetUri = generateMagnetUri(video, file, trackerUrls)
-
-    const tmpPath = await downloadWebTorrentVideo({ magnetUri }, VIDEO_IMPORT_TIMEOUT)
+    const tmpPath = await downloadWebTorrentVideo({ uri: file.torrentUrl }, VIDEO_IMPORT_TIMEOUT)
 
     const destPath = join(CONFIG.STORAGE.REDUNDANCY_DIR, file.filename)
     await move(tmpPath, destPath, { overwrite: true })
index 5e8d29d0a9b5a3e7039aba94d499f8bc087830b1..106f9602b69eedfaedb9f8f2f4ca46fbdef264af 100644 (file)
@@ -194,6 +194,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
   @Column
   metadataUrl: string
 
+  // Could be null for remote files
   @AllowNull(true)
   @Column
   fileUrl: string
@@ -203,6 +204,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
   @Column
   filename: string
 
+  // Could be null for remote files
   @AllowNull(true)
   @Column
   torrentUrl: string