]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/pods.js
Server: forbid to remove the root user
[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 = {
c4403b29
C
8 makeFriends,
9 podsAdd
9f10b292
C
10}
11
12function makeFriends (req, res, next) {
d57d6f26 13 req.checkBody('urls', 'Should have an array of unique urls').isEachUniqueUrlValid()
1e2564d3
C
14
15 logger.debug('Checking makeFriends parameters', { parameters: req.body })
16
d57d6f26
C
17 checkErrors(req, res, function () {
18 friends.hasFriends(function (err, hasFriends) {
19 if (err) {
20 logger.error('Cannot know if we have friends.', { error: err })
21 res.sendStatus(500)
22 }
23
24 if (hasFriends === true) {
25 // We need to quit our friends before make new ones
26 res.sendStatus(409)
27 } else {
28 return next()
29 }
30 })
9f10b292
C
31 })
32}
33
34function podsAdd (req, res, next) {
528a9efa
C
35 req.checkBody('url', 'Should have an url').notEmpty().isURL({ require_protocol: true })
36 req.checkBody('publicKey', 'Should have a public key').notEmpty()
37
38 // TODO: check we don't have it already
9f10b292
C
39
40 logger.debug('Checking podsAdd parameters', { parameters: req.body })
41
42 checkErrors(req, res, next)
43}
44
45// ---------------------------------------------------------------------------
46
fc51fde0 47module.exports = validatorsPod