]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/pods.js
3 const checkErrors
= require('./utils').checkErrors
4 const constants
= require('../../initializers/constants')
5 const friends
= require('../../lib/friends')
6 const logger
= require('../../helpers/logger')
7 const utils
= require('../../helpers/utils')
9 const validatorsPod
= {
14 function makeFriends (req
, res
, next
) {
15 // Force https if the administrator wants to make friends
16 if (utils
.isTestInstance() === false && constants
.CONFIG
.WEBSERVER
.SCHEME
=== 'http') {
17 return res
.status(400).send('Cannot make friends with a non HTTPS webserver.')
20 req
.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()
22 logger
.debug('Checking makeFriends parameters', { parameters: req
.body
})
24 checkErrors(req
, res
, function () {
25 friends
.hasFriends(function (err
, hasFriends
) {
27 logger
.error('Cannot know if we have friends.', { error: err
})
31 if (hasFriends
=== true) {
32 // We need to quit our friends before make new ones
41 function podsAdd (req
, res
, next
) {
42 req
.checkBody('host', 'Should have an host').notEmpty().isURL()
43 req
.checkBody('publicKey', 'Should have a public key').notEmpty()
45 // TODO: check we don't have it already
47 logger
.debug('Checking podsAdd parameters', { parameters: req
.body
})
49 checkErrors(req
, res
, next
)
52 // ---------------------------------------------------------------------------
54 module
.exports
= validatorsPod