From dac0a5319ab1c52a0958647b1593f85339b77e29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Feb 2016 18:03:20 +0100 Subject: Split utils file --- lib/friends.js | 9 +++++---- lib/poolRequests.js | 30 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/friends.js b/lib/friends.js index e093c85c4..b0086a38b 100644 --- a/lib/friends.js +++ b/lib/friends.js @@ -8,10 +8,11 @@ var constants = require('../initializers/constants') var logger = require('../helpers/logger') + var peertubeCrypto = require('../helpers/peertubeCrypto') var Pods = require('../models/pods') var PoolRequests = require('../models/poolRequests') var poolRequests = require('../lib/poolRequests') - var utils = require('../helpers/utils') + var requests = require('../helpers/requests') var Videos = require('../models/videos') var http = config.get('webserver.https') ? 'https' : 'http' @@ -48,7 +49,7 @@ var pods_score = {} logger.info('Make friends!') - fs.readFile(utils.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { + fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { if (err) { logger.error('Cannot read public cert.', { error: err }) return callback(err) @@ -115,7 +116,7 @@ videos: videos_list } - utils.makeMultipleRetryRequest( + requests.makeMultipleRetryRequest( { method: 'POST', path: '/api/' + constants.API_VERSION + '/pods/', data: data }, pods_list, @@ -176,7 +177,7 @@ } // Announce we quit them - utils.makeMultipleRetryRequest(request, pods, function () { + requests.makeMultipleRetryRequest(request, pods, function () { Pods.removeAll(function (err) { poolRequests.activate() diff --git a/lib/poolRequests.js b/lib/poolRequests.js index 796f06149..f4ab434ad 100644 --- a/lib/poolRequests.js +++ b/lib/poolRequests.js @@ -8,7 +8,7 @@ var logger = require('../helpers/logger') var Pods = require('../models/pods') var PoolRequests = require('../models/poolRequests') - var utils = require('../helpers/utils') + var requests = require('../helpers/requests') var Videos = require('../models/videos') var timer = null @@ -40,7 +40,7 @@ // --------------------------------------------------------------------------- - function makePoolRequest (type, requests, callback) { + function makePoolRequest (type, requests_to_make, callback) { if (!callback) callback = function () {} Pods.list(function (err, pods) { @@ -51,7 +51,7 @@ sign: true, method: 'POST', path: null, - data: requests + data: requests_to_make } if (type === 'add') { @@ -65,7 +65,7 @@ var bad_pods = [] var good_pods = [] - utils.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) + requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) { if (err || (response.statusCode !== 200 && response.statusCode !== 204)) { @@ -95,7 +95,7 @@ if (pool_requests.length === 0) return - var requests = { + var requests_to_make = { add: { ids: [], requests: [] @@ -108,11 +108,11 @@ async.each(pool_requests, function (pool_request, callback_each) { if (pool_request.type === 'add') { - requests.add.requests.push(pool_request.request) - requests.add.ids.push(pool_request._id) + requests_to_make.add.requests.push(pool_request.request) + requests_to_make.add.ids.push(pool_request._id) } else if (pool_request.type === 'remove') { - requests.remove.requests.push(pool_request.request) - requests.remove.ids.push(pool_request._id) + requests_to_make.remove.requests.push(pool_request.request) + requests_to_make.remove.ids.push(pool_request._id) } else { throw new Error('Unkown pool request type.') } @@ -120,20 +120,20 @@ callback_each() }, function () { // Send the add requests - if (requests.add.requests.length !== 0) { - makePoolRequest('add', requests.add.requests, function (err) { + if (requests_to_make.add.requests.length !== 0) { + makePoolRequest('add', requests_to_make.add.requests, function (err) { if (err) logger.error('Errors when sent add pool requests.', { error: err }) - PoolRequests.removeRequests(requests.add.ids) + PoolRequests.removeRequests(requests_to_make.add.ids) }) } // Send the remove requests - if (requests.remove.requests.length !== 0) { - makePoolRequest('remove', requests.remove.requests, function (err) { + if (requests_to_make.remove.requests.length !== 0) { + makePoolRequest('remove', requests_to_make.remove.requests, function (err) { if (err) logger.error('Errors when sent remove pool requests.', { error: err }) - PoolRequests.removeRequests(requests.remove.ids) + PoolRequests.removeRequests(requests_to_make.remove.ids) }) } }) -- cgit v1.2.3