1
0
Fork 0
peertube/middlewares/reqValidators/pods.js

39 lines
1005 B
JavaScript
Raw Normal View History

2015-11-07 13:16:26 +00:00
;(function () {
'use strict'
var checkErrors = require('./utils').checkErrors
2016-02-04 20:10:33 +00:00
var friends = require('../../lib/friends')
2016-01-30 16:05:22 +00:00
var logger = require('../../helpers/logger')
2015-11-07 13:16:26 +00:00
2016-01-31 10:23:52 +00:00
var reqValidatorsPod = {
2016-02-04 20:10:33 +00:00
makeFriends: makeFriends,
2016-01-31 10:23:52 +00:00
podsAdd: podsAdd
}
2015-11-07 13:16:26 +00:00
2016-02-04 20:10:33 +00:00
function makeFriends (req, res, next) {
friends.hasFriends(function (err, has_friends) {
if (err) return next(err)
if (has_friends === true) {
// We need to quit our friends before make new ones
res.sendStatus(409)
} else {
next()
}
})
}
2016-01-31 10:23:52 +00:00
function podsAdd (req, res, next) {
2015-11-07 13:16:26 +00:00
req.checkBody('data.url', 'Should have an url').notEmpty().isURL({ require_protocol: true })
req.checkBody('data.publicKey', 'Should have a public key').notEmpty()
logger.debug('Checking podsAdd parameters', { parameters: req.body })
checkErrors(req, res, next)
}
2016-01-31 10:23:52 +00:00
// ---------------------------------------------------------------------------
module.exports = reqValidatorsPod
2015-11-07 13:16:26 +00:00
})()