diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-11 21:19:34 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-13 14:23:11 +0200 |
commit | bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01 (patch) | |
tree | a1fe1ad88afd29ee4d7cb05c480649d5a9c6f9a0 /server/helpers | |
parent | 881a5e68b64e4acd43408852bbdc914643d8fac6 (diff) | |
download | PeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.tar.gz PeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.tar.zst PeerTube-bc503c2a62dcf9aed6b8d90b68f0f27a7755ac01.zip |
Update to standard 7. Goodbye snake_case, I used to love you
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/peertubeCrypto.js | 20 | ||||
-rw-r--r-- | server/helpers/requests.js | 30 | ||||
-rw-r--r-- | server/helpers/utils.js | 4 |
3 files changed, 27 insertions, 27 deletions
diff --git a/server/helpers/peertubeCrypto.js b/server/helpers/peertubeCrypto.js index 3826ebaf6..46dff8d03 100644 --- a/server/helpers/peertubeCrypto.js +++ b/server/helpers/peertubeCrypto.js | |||
@@ -21,10 +21,10 @@ const peertubeCrypto = { | |||
21 | sign: sign | 21 | sign: sign |
22 | } | 22 | } |
23 | 23 | ||
24 | function checkSignature (public_key, raw_data, hex_signature) { | 24 | function checkSignature (publicKey, rawData, hexSignature) { |
25 | const crt = ursa.createPublicKey(public_key) | 25 | const crt = ursa.createPublicKey(publicKey) |
26 | const is_valid = crt.hashAndVerify('sha256', new Buffer(raw_data).toString('hex'), hex_signature, 'hex') | 26 | const isValid = crt.hashAndVerify('sha256', new Buffer(rawData).toString('hex'), hexSignature, 'hex') |
27 | return is_valid | 27 | return isValid |
28 | } | 28 | } |
29 | 29 | ||
30 | function createCertsIfNotExist (callback) { | 30 | function createCertsIfNotExist (callback) { |
@@ -43,16 +43,16 @@ function decrypt (key, data, callback) { | |||
43 | fs.readFile(getCertDir() + 'peertube.key.pem', function (err, file) { | 43 | fs.readFile(getCertDir() + 'peertube.key.pem', function (err, file) { |
44 | if (err) return callback(err) | 44 | if (err) return callback(err) |
45 | 45 | ||
46 | const my_private_key = ursa.createPrivateKey(file) | 46 | const myPrivateKey = ursa.createPrivateKey(file) |
47 | const decrypted_key = my_private_key.decrypt(key, 'hex', 'utf8') | 47 | const decryptedKey = myPrivateKey.decrypt(key, 'hex', 'utf8') |
48 | const decrypted_data = symetricDecrypt(data, decrypted_key) | 48 | const decryptedData = symetricDecrypt(data, decryptedKey) |
49 | 49 | ||
50 | return callback(null, decrypted_data) | 50 | return callback(null, decryptedData) |
51 | }) | 51 | }) |
52 | } | 52 | } |
53 | 53 | ||
54 | function encrypt (public_key, data, callback) { | 54 | function encrypt (publicKey, data, callback) { |
55 | const crt = ursa.createPublicKey(public_key) | 55 | const crt = ursa.createPublicKey(publicKey) |
56 | 56 | ||
57 | symetricEncrypt(data, function (err, dataEncrypted) { | 57 | symetricEncrypt(data, function (err, dataEncrypted) { |
58 | if (err) return callback(err) | 58 | if (err) return callback(err) |
diff --git a/server/helpers/requests.js b/server/helpers/requests.js index 17b1127c0..1e1bb4111 100644 --- a/server/helpers/requests.js +++ b/server/helpers/requests.js | |||
@@ -17,7 +17,7 @@ const requests = { | |||
17 | makeMultipleRetryRequest: makeMultipleRetryRequest | 17 | makeMultipleRetryRequest: makeMultipleRetryRequest |
18 | } | 18 | } |
19 | 19 | ||
20 | function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) { | 20 | function makeMultipleRetryRequest (allData, pods, callbackEach, callback) { |
21 | if (!callback) { | 21 | if (!callback) { |
22 | callback = callbackEach | 22 | callback = callbackEach |
23 | callbackEach = null | 23 | callbackEach = null |
@@ -27,32 +27,32 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) { | |||
27 | let 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 (allData.method === 'POST' && allData.data && allData.sign === true) { |
31 | signature = peertubeCrypto.sign(url) | 31 | signature = peertubeCrypto.sign(url) |
32 | } | 32 | } |
33 | 33 | ||
34 | // Make a request for each pod | 34 | // Make a request for each pod |
35 | async.each(pods, function (pod, callback_each_async) { | 35 | async.each(pods, function (pod, callbackEachAsync) { |
36 | function callbackEachRetryRequest (err, response, body, url, pod) { | 36 | function callbackEachRetryRequest (err, response, body, url, pod) { |
37 | if (callbackEach !== null) { | 37 | if (callbackEach !== null) { |
38 | callbackEach(err, response, body, url, pod, function () { | 38 | callbackEach(err, response, body, url, pod, function () { |
39 | callback_each_async() | 39 | callbackEachAsync() |
40 | }) | 40 | }) |
41 | } else { | 41 | } else { |
42 | callback_each_async() | 42 | callbackEachAsync() |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | const params = { | 46 | const params = { |
47 | url: pod.url + all_data.path, | 47 | url: pod.url + allData.path, |
48 | method: all_data.method | 48 | method: allData.method |
49 | } | 49 | } |
50 | 50 | ||
51 | // Add data with POST requst ? | 51 | // Add data with POST requst ? |
52 | if (all_data.method === 'POST' && all_data.data) { | 52 | if (allData.method === 'POST' && allData.data) { |
53 | // Encrypt data ? | 53 | // Encrypt data ? |
54 | if (all_data.encrypt === true) { | 54 | if (allData.encrypt === true) { |
55 | peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) { | 55 | peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(allData.data), function (err, encrypted) { |
56 | if (err) return callback(err) | 56 | if (err) return callback(err) |
57 | 57 | ||
58 | params.json = { | 58 | params.json = { |
@@ -63,7 +63,7 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) { | |||
63 | makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) | 63 | makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) |
64 | }) | 64 | }) |
65 | } else { | 65 | } else { |
66 | params.json = { data: all_data.data } | 66 | params.json = { data: allData.data } |
67 | makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) | 67 | makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) |
68 | } | 68 | } |
69 | } else { | 69 | } else { |
@@ -78,20 +78,20 @@ module.exports = requests | |||
78 | 78 | ||
79 | // --------------------------------------------------------------------------- | 79 | // --------------------------------------------------------------------------- |
80 | 80 | ||
81 | function makeRetryRequest (params, from_url, to_pod, signature, callbackEach) { | 81 | function makeRetryRequest (params, fromUrl, toPod, signature, callbackEach) { |
82 | // Append the signature | 82 | // Append the signature |
83 | if (signature) { | 83 | if (signature) { |
84 | params.json.signature = { | 84 | params.json.signature = { |
85 | url: from_url, | 85 | url: fromUrl, |
86 | signature: signature | 86 | signature: signature |
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | logger.debug('Make retry requests to %s.', to_pod.url) | 90 | logger.debug('Make retry requests to %s.', toPod.url) |
91 | 91 | ||
92 | replay( | 92 | replay( |
93 | request.post(params, function (err, response, body) { | 93 | request.post(params, function (err, response, body) { |
94 | callbackEach(err, response, body, params.url, to_pod) | 94 | callbackEach(err, response, body, params.url, toPod) |
95 | }), | 95 | }), |
96 | { | 96 | { |
97 | retries: constants.REQUEST_RETRIES, | 97 | retries: constants.REQUEST_RETRIES, |
diff --git a/server/helpers/utils.js b/server/helpers/utils.js index 9d4d51c46..a77116e08 100644 --- a/server/helpers/utils.js +++ b/server/helpers/utils.js | |||
@@ -17,9 +17,9 @@ function generateRandomString (size, callback) { | |||
17 | }) | 17 | }) |
18 | } | 18 | } |
19 | 19 | ||
20 | function cleanForExit (webtorrent_process) { | 20 | function cleanForExit (webtorrentProcess) { |
21 | logger.info('Gracefully exiting.') | 21 | logger.info('Gracefully exiting.') |
22 | process.kill(-webtorrent_process.pid) | 22 | process.kill(-webtorrentProcess.pid) |
23 | } | 23 | } |
24 | 24 | ||
25 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |