mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Add timeout on youtube dl to cleaup files
This commit is contained in:
parent
2a27c451f7
commit
cf9166cf2f
5 changed files with 30 additions and 17 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { logger } from './logger'
|
|||
import { generateVideoTmpPath } from './utils'
|
||||
import { join } from 'path'
|
||||
import { root } from './core-utils'
|
||||
import { ensureDir, writeFile } from 'fs-extra'
|
||||
import { ensureDir, writeFile, remove } from 'fs-extra'
|
||||
import * as request from 'request'
|
||||
import { createWriteStream } from 'fs'
|
||||
|
||||
|
@ -39,8 +39,9 @@ function getYoutubeDLInfo (url: string, opts?: string[]): Promise<YoutubeDLInfo>
|
|||
})
|
||||
}
|
||||
|
||||
function downloadYoutubeDLVideo (url: string) {
|
||||
function downloadYoutubeDLVideo (url: string, timeout: number) {
|
||||
const path = generateVideoTmpPath(url)
|
||||
let timer
|
||||
|
||||
logger.info('Importing youtubeDL video %s', url)
|
||||
|
||||
|
@ -49,10 +50,23 @@ function downloadYoutubeDLVideo (url: string) {
|
|||
return new Promise<string>(async (res, rej) => {
|
||||
const youtubeDL = await safeGetYoutubeDL()
|
||||
youtubeDL.exec(url, options, processOptions, err => {
|
||||
if (err) return rej(err)
|
||||
clearTimeout(timer)
|
||||
|
||||
if (err) {
|
||||
remove(path)
|
||||
.catch(err => logger.error('Cannot delete path on YoutubeDL error.', { err }))
|
||||
|
||||
return rej(err)
|
||||
}
|
||||
|
||||
return res(path)
|
||||
})
|
||||
|
||||
timer = setTimeout(async () => {
|
||||
await remove(path)
|
||||
|
||||
return rej(new Error('YoutubeDL download timeout.'))
|
||||
}, timeout)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue