1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Add timeout on youtube dl to cleaup files

This commit is contained in:
Chocobozzz 2018-10-01 12:00:05 +02:00
parent 2a27c451f7
commit cf9166cf2f
No known key found for this signature in database
GPG key ID: 583A612D890159BE
5 changed files with 30 additions and 17 deletions

View file

@ -5,7 +5,7 @@ import { createWriteStream, ensureDir, remove } from 'fs-extra'
import { CONFIG } from '../initializers'
import { dirname, join } from 'path'
async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout?: number) {
async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) {
const id = target.magnetUri || target.torrentName
let timer
@ -50,12 +50,10 @@ async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName
torrent.on('error', err => rej(err))
if (timeout) {
timer = setTimeout(async () => {
return safeWebtorrentDestroy(webtorrent, torrentId, file ? { directoryPath, filepath: file.path } : undefined, target.torrentName)
.then(() => rej(new Error('Webtorrent download timeout.')))
}, timeout)
}
timer = setTimeout(async () => {
return safeWebtorrentDestroy(webtorrent, torrentId, file ? { directoryPath, filepath: file.path } : undefined, target.torrentName)
.then(() => rej(new Error('Webtorrent download timeout.')))
}, timeout)
})
}