diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-01 12:00:05 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-01 12:00:05 +0200 |
commit | cf9166cf2fb7b51a1137a259eed9338798c73500 (patch) | |
tree | 7cf4b5995d4a29cc335e1fd72c1572510f8432ad /server/helpers/webtorrent.ts | |
parent | 2a27c451f78922107c3f056e7506be8a79b31e03 (diff) | |
download | PeerTube-cf9166cf2fb7b51a1137a259eed9338798c73500.tar.gz PeerTube-cf9166cf2fb7b51a1137a259eed9338798c73500.tar.zst PeerTube-cf9166cf2fb7b51a1137a259eed9338798c73500.zip |
Add timeout on youtube dl to cleaup files
Diffstat (limited to 'server/helpers/webtorrent.ts')
-rw-r--r-- | server/helpers/webtorrent.ts | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 924d630e7..ce35b87da 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -5,7 +5,7 @@ import { createWriteStream, ensureDir, remove } from 'fs-extra' | |||
5 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
6 | import { dirname, join } from 'path' | 6 | import { dirname, join } from 'path' |
7 | 7 | ||
8 | async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout?: number) { | 8 | async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) { |
9 | const id = target.magnetUri || target.torrentName | 9 | const id = target.magnetUri || target.torrentName |
10 | let timer | 10 | let timer |
11 | 11 | ||
@@ -50,12 +50,10 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName | |||
50 | 50 | ||
51 | torrent.on('error', err => rej(err)) | 51 | torrent.on('error', err => rej(err)) |
52 | 52 | ||
53 | if (timeout) { | 53 | timer = setTimeout(async () => { |
54 | timer = setTimeout(async () => { | 54 | return safeWebtorrentDestroy(webtorrent, torrentId, file ? { directoryPath, filepath: file.path } : undefined, target.torrentName) |
55 | return safeWebtorrentDestroy(webtorrent, torrentId, file ? { directoryPath, filepath: file.path } : undefined, target.torrentName) | 55 | .then(() => rej(new Error('Webtorrent download timeout.'))) |
56 | .then(() => rej(new Error('Webtorrent download timeout.'))) | 56 | }, timeout) |
57 | }, timeout) | ||
58 | } | ||
59 | }) | 57 | }) |
60 | } | 58 | } |
61 | 59 | ||