diff options
-rw-r--r-- | server/helpers/webtorrent.ts | 15 |
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 @@ | |||
1 | import { logger } from './logger' | 1 | import { logger } from './logger' |
2 | import { generateVideoTmpPath } from './utils' | 2 | import { generateVideoTmpPath } from './utils' |
3 | import * as WebTorrent from 'webtorrent' | 3 | import * as WebTorrent from 'webtorrent' |
4 | import { createWriteStream, remove } from 'fs-extra' | 4 | import { remove } from 'fs-extra' |
5 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
6 | import { join } from 'path' | 6 | import { 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)) |