aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-25 17:48:45 +0200
committerChocobozzz <me@florianbigard.com>2018-09-25 17:49:50 +0200
commitc922d14220eed241d47677db8441921935435f0c (patch)
treea1248e9bdac7ea88c3d5790ba17b6d63064f8a62 /server
parentcfaf819c38dc0de996c9844e5ef0ee364944d41f (diff)
downloadPeerTube-c922d14220eed241d47677db8441921935435f0c.tar.gz
PeerTube-c922d14220eed241d47677db8441921935435f0c.tar.zst
PeerTube-c922d14220eed241d47677db8441921935435f0c.zip
Fix redundancy bug with old peertube torrent
Diffstat (limited to 'server')
-rw-r--r--server/helpers/webtorrent.ts15
1 files changed, 2 insertions, 13 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index f4b44bc4f..d35b3a710 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -1,7 +1,7 @@
1import { logger } from './logger' 1import { logger } from './logger'
2import { generateVideoTmpPath } from './utils' 2import { generateVideoTmpPath } from './utils'
3import * as WebTorrent from 'webtorrent' 3import * as WebTorrent from 'webtorrent'
4import { createWriteStream, remove } from 'fs-extra' 4import { remove } from 'fs-extra'
5import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers'
6import { join } from 'path' 6import { join } from 'path'
7 7
@@ -9,7 +9,6 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: str
9 const id = target.magnetUri || target.torrentName 9 const id = target.magnetUri || target.torrentName
10 let timer 10 let timer
11 11
12 const path = generateVideoTmpPath(id)
13 logger.info('Importing torrent video %s', id) 12 logger.info('Importing torrent video %s', id)
14 13
15 return new Promise<string>((res, rej) => { 14 return new Promise<string>((res, rej) => {
@@ -27,17 +26,7 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: str
27 .then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it'))) 26 .then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it')))
28 } 27 }
29 28
30 file = torrent.files[ 0 ] 29 torrent.on('done', () => res(join(CONFIG.STORAGE.VIDEOS_DIR, torrent.files[ 0 ].path)))
31
32 const writeStream = createWriteStream(path)
33 writeStream.on('finish', () => {
34 if (timer) clearTimeout(timer)
35
36 return safeWebtorrentDestroy(webtorrent, torrentId, file.name, target.torrentName)
37 .then(() => res(path))
38 })
39
40 file.createReadStream().pipe(writeStream)
41 }) 30 })
42 31
43 torrent.on('error', err => rej(err)) 32 torrent.on('error', err => rej(err))