import { logger } from './logger'
import { generateVideoImportTmpPath } from './utils'
import { extractVideo } from './video'
+import { pipeline } from 'stream'
const createTorrentPromise = promisify2<string, any, any>(createTorrent)
.then(() => rej(new Error('Cannot import torrent ' + torrentId + ': there are multiple files in it')))
}
+ logger.debug('Got torrent from webtorrent %s.', id, { infoHash: torrent.infoHash, files: torrent.files })
+
file = torrent.files[0]
// FIXME: avoid creating another stream when https://github.com/webtorrent/webtorrent/issues/1517 is fixed
.catch(err => logger.error('Cannot destroy webtorrent.', { err }))
})
- file.createReadStream().pipe(writeStream)
+ pipeline(
+ file.createReadStream(),
+ writeStream,
+ err => rej(err)
+ )
})
torrent.on('error', err => rej(err))
private async isTooHeavy (candidateToDuplicate: CandidateToDuplicate) {
const maxSize = candidateToDuplicate.redundancy.size
- const { totalUsed: used } = await VideoRedundancyModel.getStats(candidateToDuplicate.redundancy.strategy)
+ const { totalUsed: alreadyUsed } = await VideoRedundancyModel.getStats(candidateToDuplicate.redundancy.strategy)
const videoSize = this.getTotalFileSizes(candidateToDuplicate.files, candidateToDuplicate.streamingPlaylists)
- const total = used + videoSize
+ const willUse = alreadyUsed + videoSize
- logger.debug('Checking candidate size.', { used, videoSize, total, ...lTags(candidateToDuplicate.video.uuid) })
+ logger.debug('Checking candidate size.', { maxSize, alreadyUsed, videoSize, willUse, ...lTags(candidateToDuplicate.video.uuid) })
- return total > maxSize
+ return willUse > maxSize
}
private buildNewExpiration (expiresAfterMs: number) {