Fix redundancy bug with old peertube torrent
This commit is contained in:
parent
cfaf819c38
commit
c922d14220
|
@ -1,7 +1,7 @@
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
import { generateVideoTmpPath } from './utils'
|
import { generateVideoTmpPath } from './utils'
|
||||||
import * as WebTorrent from 'webtorrent'
|
import * as WebTorrent from 'webtorrent'
|
||||||
import { createWriteStream, remove } from 'fs-extra'
|
import { remove } from 'fs-extra'
|
||||||
import { CONFIG } from '../initializers'
|
import { CONFIG } from '../initializers'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: str
|
||||||
const id = target.magnetUri || target.torrentName
|
const id = target.magnetUri || target.torrentName
|
||||||
let timer
|
let timer
|
||||||
|
|
||||||
const path = generateVideoTmpPath(id)
|
|
||||||
logger.info('Importing torrent video %s', id)
|
logger.info('Importing torrent video %s', id)
|
||||||
|
|
||||||
return new Promise<string>((res, rej) => {
|
return new Promise<string>((res, rej) => {
|
||||||
|
@ -27,17 +26,7 @@ function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: str
|
||||||
.then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it')))
|
.then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it')))
|
||||||
}
|
}
|
||||||
|
|
||||||
file = torrent.files[ 0 ]
|
torrent.on('done', () => res(join(CONFIG.STORAGE.VIDEOS_DIR, torrent.files[ 0 ].path)))
|
||||||
|
|
||||||
const writeStream = createWriteStream(path)
|
|
||||||
writeStream.on('finish', () => {
|
|
||||||
if (timer) clearTimeout(timer)
|
|
||||||
|
|
||||||
return safeWebtorrentDestroy(webtorrent, torrentId, file.name, target.torrentName)
|
|
||||||
.then(() => res(path))
|
|
||||||
})
|
|
||||||
|
|
||||||
file.createReadStream().pipe(writeStream)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
torrent.on('error', err => rej(err))
|
torrent.on('error', err => rej(err))
|
||||||
|
|
Loading…
Reference in New Issue