diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-03-16 22:29:27 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-03-16 22:29:27 +0100 |
commit | f0f5567b6918fc60c8cab15e13aec03a89a91dfb (patch) | |
tree | 99dfdb9fa8273c9cda1360fd3b6bfccc515bf8be /server/helpers/requests.js | |
parent | 5101105ef91bfe478f97546b78b321882da2079c (diff) | |
download | PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.gz PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.zst PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.zip |
Use const/let now we use node 4.2
Diffstat (limited to 'server/helpers/requests.js')
-rw-r--r-- | server/helpers/requests.js | 51 |
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 | ||
3 | var async = require('async') | 3 | const async = require('async') |
4 | var config = require('config') | 4 | const config = require('config') |
5 | var request = require('request') | 5 | const request = require('request') |
6 | var replay = require('request-replay') | 6 | const replay = require('request-replay') |
7 | 7 | ||
8 | var constants = require('../initializers/constants') | 8 | const constants = require('../initializers/constants') |
9 | var logger = require('./logger') | 9 | const logger = require('./logger') |
10 | var peertubeCrypto = require('./peertubeCrypto') | 10 | const peertubeCrypto = require('./peertubeCrypto') |
11 | 11 | ||
12 | var http = config.get('webserver.https') ? 'https' : 'http' | 12 | const http = config.get('webserver.https') ? 'https' : 'http' |
13 | var host = config.get('webserver.host') | 13 | const host = config.get('webserver.host') |
14 | var port = config.get('webserver.port') | 14 | const port = config.get('webserver.port') |
15 | 15 | ||
16 | var requests = { | 16 | const 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) |