]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/requests.js
Server: request scheduler refractoring
[github/Chocobozzz/PeerTube.git] / server / helpers / requests.js
index 06109ce168d4e8182248590e510aa7950889dc59..42786411725ce8980bd3d017497567eb1f10ccb9 100644 (file)
@@ -28,44 +28,39 @@ function makeSecureRequest (params, callback) {
     url: constants.REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path
   }
 
-  // Add data with POST requst ?
-  if (params.method === 'POST') {
-    requestParams.json = {}
+  if (params.method !== 'POST') {
+    return callback(new Error('Cannot make a secure request with a non POST method.'))
+  }
 
-    // Add signature if it is specified in the params
-    if (params.sign === true) {
-      const host = constants.CONFIG.WEBSERVER.HOST
+  requestParams.json = {}
 
-      requestParams.json.signature = {
-        host,
-        signature: peertubeCrypto.sign(host)
-      }
-    }
+  // Add signature if it is specified in the params
+  if (params.sign === true) {
+    const host = constants.CONFIG.WEBSERVER.HOST
 
-    // If there are data informations
+    let dataToSign
     if (params.data) {
-      // Encrypt data
-      if (params.encrypt === true) {
-        peertubeCrypto.encrypt(params.toPod.publicKey, JSON.stringify(params.data), function (err, encrypted) {
-          if (err) return callback(err)
-
-          requestParams.json.data = encrypted.data
-          requestParams.json.key = encrypted.key
-
-          request.post(requestParams, callback)
-        })
-      } else {
-        // No encryption
-        requestParams.json.data = params.data
-        request.post(requestParams, callback)
-      }
+      dataToSign = dataToSign = params.data
     } else {
-      // No data
-      request.post(requestParams, callback)
+      // We do not have data to sign so we just take our host
+      // It is not ideal but the connection should be in HTTPS
+      dataToSign = host
+    }
+
+    requestParams.json.signature = {
+      host, // Which host we pretend to be
+      signature: peertubeCrypto.sign(dataToSign)
     }
-  } else {
-    request.get(requestParams, callback)
   }
+
+  // If there are data informations
+  if (params.data) {
+    requestParams.json.data = params.data
+  }
+
+  console.log(requestParams.json.data)
+
+  request.post(requestParams, callback)
 }
 
 // ---------------------------------------------------------------------------