]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - middlewares/reqValidators/pods.js
4d649b486626e63a900130b5059af81e72d83199
[github/Chocobozzz/PeerTube.git] / middlewares / reqValidators / pods.js
1 ;(function () {
2 'use strict'
3
4 var checkErrors = require('./utils').checkErrors
5 var friends = require('../../lib/friends')
6 var logger = require('../../helpers/logger')
7
8 var reqValidatorsPod = {
9 makeFriends: makeFriends,
10 podsAdd: podsAdd
11 }
12
13 function makeFriends (req, res, next) {
14 friends.hasFriends(function (err, has_friends) {
15 if (err) {
16 logger.error('Cannot know if we have friends.', { error: err })
17 res.sendStatus(500)
18 }
19
20 if (has_friends === true) {
21 // We need to quit our friends before make new ones
22 res.sendStatus(409)
23 } else {
24 next()
25 }
26 })
27 }
28
29 function podsAdd (req, res, next) {
30 req.checkBody('data.url', 'Should have an url').notEmpty().isURL({ require_protocol: true })
31 req.checkBody('data.publicKey', 'Should have a public key').notEmpty()
32
33 logger.debug('Checking podsAdd parameters', { parameters: req.body })
34
35 checkErrors(req, res, next)
36 }
37
38 // ---------------------------------------------------------------------------
39
40 module.exports = reqValidatorsPod
41 })()