aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/requests.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/requests.js')
-rw-r--r--server/helpers/requests.js51
1 files changed, 24 insertions, 27 deletions
diff --git a/server/helpers/requests.js b/server/helpers/requests.js
index e19afa5ca..17b1127c0 100644
--- a/server/helpers/requests.js
+++ b/server/helpers/requests.js
@@ -1,19 +1,19 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var config = require('config') 4const config = require('config')
5var request = require('request') 5const request = require('request')
6var replay = require('request-replay') 6const replay = require('request-replay')
7 7
8var constants = require('../initializers/constants') 8const constants = require('../initializers/constants')
9var logger = require('./logger') 9const logger = require('./logger')
10var peertubeCrypto = require('./peertubeCrypto') 10const peertubeCrypto = require('./peertubeCrypto')
11 11
12var http = config.get('webserver.https') ? 'https' : 'http' 12const http = config.get('webserver.https') ? 'https' : 'http'
13var host = config.get('webserver.host') 13const host = config.get('webserver.host')
14var port = config.get('webserver.port') 14const port = config.get('webserver.port')
15 15
16var requests = { 16const requests = {
17 makeMultipleRetryRequest: makeMultipleRetryRequest 17 makeMultipleRetryRequest: makeMultipleRetryRequest
18} 18}
19 19
@@ -23,8 +23,8 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
23 callbackEach = null 23 callbackEach = null
24 } 24 }
25 25
26 var url = http + '://' + host + ':' + port 26 const url = http + '://' + host + ':' + port
27 var signature 27 let signature
28 28
29 // Add signature if it is specified in the params 29 // Add signature if it is specified in the params
30 if (all_data.method === 'POST' && all_data.data && all_data.sign === true) { 30 if (all_data.method === 'POST' && all_data.data && all_data.sign === true) {
@@ -43,7 +43,7 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
43 } 43 }
44 } 44 }
45 45
46 var params = { 46 const params = {
47 url: pod.url + all_data.path, 47 url: pod.url + all_data.path,
48 method: all_data.method 48 method: all_data.method
49 } 49 }
@@ -52,19 +52,16 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
52 if (all_data.method === 'POST' && all_data.data) { 52 if (all_data.method === 'POST' && all_data.data) {
53 // Encrypt data ? 53 // Encrypt data ?
54 if (all_data.encrypt === true) { 54 if (all_data.encrypt === true) {
55 // TODO: ES6 with let 55 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) {
56 ;(function (copy_params, copy_url, copy_pod, copy_signature) { 56 if (err) return callback(err)
57 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) { 57
58 if (err) return callback(err) 58 params.json = {
59 59 data: encrypted.data,
60 copy_params.json = { 60 key: encrypted.key
61 data: encrypted.data, 61 }
62 key: encrypted.key 62
63 } 63 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
64 64 })
65 makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEachRetryRequest)
66 })
67 })(params, url, pod, signature)
68 } else { 65 } else {
69 params.json = { data: all_data.data } 66 params.json = { data: all_data.data }
70 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) 67 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)