+ writeStream.on('finish', () => {
+ webtorrent.destroy(async err => {
+ if (err) return rej(err)
+
+ if (target.torrentName) {
+ unlinkPromise(torrentId)
+ .catch(err => logger.error('Cannot remove torrent %s in webtorrent download.', torrentId, { err }))
+ }
+
+ unlinkPromise(join(CONFIG.STORAGE.VIDEOS_DIR, file.name))
+ .catch(err => logger.error('Cannot remove torrent file %s in webtorrent download.', file.name, { err }))
+
+ res(path)
+ })
+ })