aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/webtorrent.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r--server/helpers/webtorrent.ts9
1 files changed, 8 insertions, 1 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index becad533e..5fe4c1165 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -17,6 +17,7 @@ import { promisify2 } from './core-utils'
17import { logger } from './logger' 17import { logger } from './logger'
18import { generateVideoImportTmpPath } from './utils' 18import { generateVideoImportTmpPath } from './utils'
19import { extractVideo } from './video' 19import { extractVideo } from './video'
20import { pipeline } from 'stream'
20 21
21const createTorrentPromise = promisify2<string, any, any>(createTorrent) 22const createTorrentPromise = promisify2<string, any, any>(createTorrent)
22 23
@@ -49,6 +50,8 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
49 .then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it'))) 50 .then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it')))
50 } 51 }
51 52
53 logger.debug('Got torrent from webtorrent %s.', id, { infoHash: torrent.infoHash, files: torrent.files })
54
52 file = torrent.files[0] 55 file = torrent.files[0]
53 56
54 // FIXME: avoid creating another stream when https://github.com/webtorrent/webtorrent/issues/1517 is fixed 57 // FIXME: avoid creating another stream when https://github.com/webtorrent/webtorrent/issues/1517 is fixed
@@ -61,7 +64,11 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
61 .catch(err => logger.error('Cannot destroy webtorrent.', { err })) 64 .catch(err => logger.error('Cannot destroy webtorrent.', { err }))
62 }) 65 })
63 66
64 file.createReadStream().pipe(writeStream) 67 pipeline(
68 file.createReadStream(),
69 writeStream,
70 err => rej(err)
71 )
65 }) 72 })
66 73
67 torrent.on('error', err => rej(err)) 74 torrent.on('error', err => rej(err))