]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/pods.js
Server: put config in constants
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / pods.js
CommitLineData
9f10b292
C
1'use strict'
2
f0f5567b
C
3const checkErrors = require('./utils').checkErrors
4const friends = require('../../lib/friends')
5const logger = require('../../helpers/logger')
9f10b292 6
fc51fde0 7const validatorsPod = {
9f10b292
C
8 makeFriends: makeFriends,
9 podsAdd: podsAdd
10}
11
12function makeFriends (req, res, next) {
bc503c2a 13 friends.hasFriends(function (err, hasFriends) {
9f10b292
C
14 if (err) {
15 logger.error('Cannot know if we have friends.', { error: err })
16 res.sendStatus(500)
17 }
18
bc503c2a 19 if (hasFriends === true) {
9f10b292
C
20 // We need to quit our friends before make new ones
21 res.sendStatus(409)
22 } else {
1bfd1a92 23 return next()
9f10b292
C
24 }
25 })
26}
27
28function podsAdd (req, res, next) {
528a9efa
C
29 req.checkBody('url', 'Should have an url').notEmpty().isURL({ require_protocol: true })
30 req.checkBody('publicKey', 'Should have a public key').notEmpty()
31
32 // TODO: check we don't have it already
9f10b292
C
33
34 logger.debug('Checking podsAdd parameters', { parameters: req.body })
35
36 checkErrors(req, res, next)
37}
38
39// ---------------------------------------------------------------------------
40
fc51fde0 41module.exports = validatorsPod