function addVideoToFriends (video) {
// To avoid duplicates
var id = video.name + video.magnetUri
- // namePath is null
- // TODO
+ // ensure namePath is null
video.namePath = null
PoolRequests.addRequest(id, 'add', video)
}
logger.info('Make friends!')
fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) {
if (err) {
- logger.error('Cannot read public cert.', { error: err })
+ logger.error('Cannot read public cert.')
return callback(err)
}
var urls = config.get('network.friends')
- async.each(urls, computeForeignPodsList, function () {
+ async.each(urls, computeForeignPodsList, function (err) {
+ if (err) return callback(err)
+
logger.debug('Pods scores computed.', { pods_score: pods_score })
var pods_list = computeWinningPods(urls, pods_score)
logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list })
// Let's give 1 point to the pod we ask the friends list
pods_score[url] = 1
- getForeignPodsList(url, function (foreign_pods_list) {
+ getForeignPodsList(url, function (err, foreign_pods_list) {
+ if (err) return callback(err)
if (foreign_pods_list.length === 0) return callback()
async.each(foreign_pods_list, function (foreign_pod, callback_each) {
// Get the list of our videos to send to our new friends
Videos.listOwned(function (err, videos_list) {
- if (err) throw err
+ if (err) {
+ logger.error('Cannot get the list of videos we own.')
+ return callback(err)
+ }
var data = {
url: http + '://' + host + ':' + port,
poolRequests.activate()
if (err) {
- logger.error('There was some errors when we wanted to make friends.', { error: err })
+ logger.error('There was some errors when we wanted to make friends.')
return callback(err)
}
var path = '/api/' + constants.API_VERSION + '/pods'
request.get(url + path, function (err, response, body) {
- if (err) throw err
- callback(JSON.parse(body))
+ if (err) return callback(err)
+
+ callback(null, JSON.parse(body))
})
}
})()