X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=lib%2Ffriends.js;h=badf09c7dd7e6d184978d2479c117315ec4c524a;hb=8425cb894d4867d26fd5f7fae7862b0669f3c717;hp=b0086a38b78e1fb2b1cc6e53139d0050afff7d05;hpb=dac0a5319ab1c52a0958647b1593f85339b77e29;p=github%2FChocobozzz%2FPeerTube.git diff --git a/lib/friends.js b/lib/friends.js index b0086a38b..badf09c7d 100644 --- a/lib/friends.js +++ b/lib/friends.js @@ -30,8 +30,7 @@ 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) } @@ -51,13 +50,15 @@ 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 }) @@ -72,7 +73,8 @@ // 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) { @@ -108,7 +110,10 @@ // 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, @@ -145,7 +150,7 @@ 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) } @@ -212,8 +217,9 @@ 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)) }) } })()