X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=middlewares%2Fmisc.js;h=dbb604db34d63f19a8e95e15d2c18d9db163e578;hb=c45f7f84001c2731909db04dd82e1c1f290386eb;hp=f814acd9f0bae62e82e1be15466b8514fa4507ac;hpb=cda021079ff455cc0fd0eb95a5395fa808ab63d1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/middlewares/misc.js b/middlewares/misc.js index f814acd9f..dbb604db3 100644 --- a/middlewares/misc.js +++ b/middlewares/misc.js @@ -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 })()