aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-02-05 18:03:20 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-02-05 18:03:20 +0100
commitdac0a5319ab1c52a0958647b1593f85339b77e29 (patch)
tree716bc9e7e0b9fd3a7066530e50e73991fb278d05 /lib
parenta5fa04b0cce851f680a45055f57ed2c3d22f1c82 (diff)
downloadPeerTube-dac0a5319ab1c52a0958647b1593f85339b77e29.tar.gz
PeerTube-dac0a5319ab1c52a0958647b1593f85339b77e29.tar.zst
PeerTube-dac0a5319ab1c52a0958647b1593f85339b77e29.zip
Split utils file
Diffstat (limited to 'lib')
-rw-r--r--lib/friends.js9
-rw-r--r--lib/poolRequests.js30
2 files changed, 20 insertions, 19 deletions
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 @@
8 8
9 var constants = require('../initializers/constants') 9 var constants = require('../initializers/constants')
10 var logger = require('../helpers/logger') 10 var logger = require('../helpers/logger')
11 var peertubeCrypto = require('../helpers/peertubeCrypto')
11 var Pods = require('../models/pods') 12 var Pods = require('../models/pods')
12 var PoolRequests = require('../models/poolRequests') 13 var PoolRequests = require('../models/poolRequests')
13 var poolRequests = require('../lib/poolRequests') 14 var poolRequests = require('../lib/poolRequests')
14 var utils = require('../helpers/utils') 15 var requests = require('../helpers/requests')
15 var Videos = require('../models/videos') 16 var Videos = require('../models/videos')
16 17
17 var http = config.get('webserver.https') ? 'https' : 'http' 18 var http = config.get('webserver.https') ? 'https' : 'http'
@@ -48,7 +49,7 @@
48 var pods_score = {} 49 var pods_score = {}
49 50
50 logger.info('Make friends!') 51 logger.info('Make friends!')
51 fs.readFile(utils.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { 52 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) {
52 if (err) { 53 if (err) {
53 logger.error('Cannot read public cert.', { error: err }) 54 logger.error('Cannot read public cert.', { error: err })
54 return callback(err) 55 return callback(err)
@@ -115,7 +116,7 @@
115 videos: videos_list 116 videos: videos_list
116 } 117 }
117 118
118 utils.makeMultipleRetryRequest( 119 requests.makeMultipleRetryRequest(
119 { method: 'POST', path: '/api/' + constants.API_VERSION + '/pods/', data: data }, 120 { method: 'POST', path: '/api/' + constants.API_VERSION + '/pods/', data: data },
120 121
121 pods_list, 122 pods_list,
@@ -176,7 +177,7 @@
176 } 177 }
177 178
178 // Announce we quit them 179 // Announce we quit them
179 utils.makeMultipleRetryRequest(request, pods, function () { 180 requests.makeMultipleRetryRequest(request, pods, function () {
180 Pods.removeAll(function (err) { 181 Pods.removeAll(function (err) {
181 poolRequests.activate() 182 poolRequests.activate()
182 183
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 @@
8 var logger = require('../helpers/logger') 8 var logger = require('../helpers/logger')
9 var Pods = require('../models/pods') 9 var Pods = require('../models/pods')
10 var PoolRequests = require('../models/poolRequests') 10 var PoolRequests = require('../models/poolRequests')
11 var utils = require('../helpers/utils') 11 var requests = require('../helpers/requests')
12 var Videos = require('../models/videos') 12 var Videos = require('../models/videos')
13 13
14 var timer = null 14 var timer = null
@@ -40,7 +40,7 @@
40 40
41 // --------------------------------------------------------------------------- 41 // ---------------------------------------------------------------------------
42 42
43 function makePoolRequest (type, requests, callback) { 43 function makePoolRequest (type, requests_to_make, callback) {
44 if (!callback) callback = function () {} 44 if (!callback) callback = function () {}
45 45
46 Pods.list(function (err, pods) { 46 Pods.list(function (err, pods) {
@@ -51,7 +51,7 @@
51 sign: true, 51 sign: true,
52 method: 'POST', 52 method: 'POST',
53 path: null, 53 path: null,
54 data: requests 54 data: requests_to_make
55 } 55 }
56 56
57 if (type === 'add') { 57 if (type === 'add') {
@@ -65,7 +65,7 @@
65 var bad_pods = [] 65 var bad_pods = []
66 var good_pods = [] 66 var good_pods = []
67 67
68 utils.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished) 68 requests.makeMultipleRetryRequest(params, pods, callbackEachPodFinished, callbackAllPodsFinished)
69 69
70 function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) { 70 function callbackEachPodFinished (err, response, body, url, pod, callback_each_pod_finished) {
71 if (err || (response.statusCode !== 200 && response.statusCode !== 204)) { 71 if (err || (response.statusCode !== 200 && response.statusCode !== 204)) {
@@ -95,7 +95,7 @@
95 95
96 if (pool_requests.length === 0) return 96 if (pool_requests.length === 0) return
97 97
98 var requests = { 98 var requests_to_make = {
99 add: { 99 add: {
100 ids: [], 100 ids: [],
101 requests: [] 101 requests: []
@@ -108,11 +108,11 @@
108 108
109 async.each(pool_requests, function (pool_request, callback_each) { 109 async.each(pool_requests, function (pool_request, callback_each) {
110 if (pool_request.type === 'add') { 110 if (pool_request.type === 'add') {
111 requests.add.requests.push(pool_request.request) 111 requests_to_make.add.requests.push(pool_request.request)
112 requests.add.ids.push(pool_request._id) 112 requests_to_make.add.ids.push(pool_request._id)
113 } else if (pool_request.type === 'remove') { 113 } else if (pool_request.type === 'remove') {
114 requests.remove.requests.push(pool_request.request) 114 requests_to_make.remove.requests.push(pool_request.request)
115 requests.remove.ids.push(pool_request._id) 115 requests_to_make.remove.ids.push(pool_request._id)
116 } else { 116 } else {
117 throw new Error('Unkown pool request type.') 117 throw new Error('Unkown pool request type.')
118 } 118 }
@@ -120,20 +120,20 @@
120 callback_each() 120 callback_each()
121 }, function () { 121 }, function () {
122 // Send the add requests 122 // Send the add requests
123 if (requests.add.requests.length !== 0) { 123 if (requests_to_make.add.requests.length !== 0) {
124 makePoolRequest('add', requests.add.requests, function (err) { 124 makePoolRequest('add', requests_to_make.add.requests, function (err) {
125 if (err) logger.error('Errors when sent add pool requests.', { error: err }) 125 if (err) logger.error('Errors when sent add pool requests.', { error: err })
126 126
127 PoolRequests.removeRequests(requests.add.ids) 127 PoolRequests.removeRequests(requests_to_make.add.ids)
128 }) 128 })
129 } 129 }
130 130
131 // Send the remove requests 131 // Send the remove requests
132 if (requests.remove.requests.length !== 0) { 132 if (requests_to_make.remove.requests.length !== 0) {
133 makePoolRequest('remove', requests.remove.requests, function (err) { 133 makePoolRequest('remove', requests_to_make.remove.requests, function (err) {
134 if (err) logger.error('Errors when sent remove pool requests.', { error: err }) 134 if (err) logger.error('Errors when sent remove pool requests.', { error: err })
135 135
136 PoolRequests.removeRequests(requests.remove.ids) 136 PoolRequests.removeRequests(requests_to_make.remove.ids)
137 }) 137 })
138 } 138 }
139 }) 139 })