]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - middlewares/misc.js
Infile code reorganization
[github/Chocobozzz/PeerTube.git] / middlewares / misc.js
index f814acd9f0bae62e82e1be15466b8514fa4507ac..dbb604db34d63f19a8e95e15d2c18d9db163e578 100644 (file)
@@ -1,16 +1,19 @@
 ;(function () {
   'use strict'
 
-  var ursa = require('ursa')
   var fs = require('fs')
+  var ursa = require('ursa')
 
   var logger = require('../helpers/logger')
-  var utils = require('../helpers/utils')
   var PodsDB = require('../initializers/database').PodsDB
+  var utils = require('../helpers/utils')
 
-  var misc = {}
+  var miscMiddleware = {
+    cache: cache,
+    decryptBody: decryptBody
+  }
 
-  misc.cache = function (cache) {
+  function cache (cache) {
     return function (req, res, next) {
       // If we want explicitly a cache
       // Or if we don't specify if we want a cache or no and we are in production
@@ -24,7 +27,7 @@
     }
   }
 
-  misc.decryptBody = function (req, res, next) {
+  function decryptBody (req, res, next) {
     PodsDB.findOne({ url: req.body.signature.url }, function (err, pod) {
       if (err) {
         logger.error('Cannot get signed url in decryptBody.', { error: err })
@@ -42,7 +45,7 @@
       var signature_ok = crt.hashAndVerify('sha256', new Buffer(req.body.signature.url).toString('hex'), req.body.signature.signature, 'hex')
 
       if (signature_ok === true) {
-        var myKey = ursa.createPrivateKey(fs.readFileSync(utils.certDir + 'peertube.key.pem'))
+        var myKey = ursa.createPrivateKey(fs.readFileSync(utils.getCertDir() + 'peertube.key.pem'))
         var decryptedKey = myKey.decrypt(req.body.key, 'hex', 'utf8')
         req.body.data = JSON.parse(utils.symetricDecrypt(req.body.data, decryptedKey))
         delete req.body.key
@@ -55,5 +58,7 @@
     })
   }
 
-  module.exports = misc
+  // ---------------------------------------------------------------------------
+
+  module.exports = miscMiddleware
 })()