]>
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 db
= require('../../initializers/database')
6 const friends
= require('../../lib/friends')
7 const logger
= require('../../helpers/logger')
8 const utils
= require('../../helpers/utils')
10 const validatorsPod
= {
15 function makeFriends (req
, res
, next
) {
16 // Force https if the administrator wants to make friends
17 if (utils
.isTestInstance() === false && constants
.CONFIG
.WEBSERVER
.SCHEME
=== 'http') {
18 return res
.status(400).send('Cannot make friends with a non HTTPS webserver.')
21 req
.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()
23 logger
.debug('Checking makeFriends parameters', { parameters: req
.body
})
25 checkErrors(req
, res
, function () {
26 friends
.hasFriends(function (err
, hasFriends
) {
28 logger
.error('Cannot know if we have friends.', { error: err
})
32 if (hasFriends
=== true) {
33 // We need to quit our friends before make new ones
34 return res
.sendStatus(409)
42 function podsAdd (req
, res
, next
) {
43 req
.checkBody('host', 'Should have a host').isHostValid()
44 req
.checkBody('email', 'Should have an email').isEmail()
45 req
.checkBody('publicKey', 'Should have a public key').notEmpty()
46 logger
.debug('Checking podsAdd parameters', { parameters: req
.body
})
48 checkErrors(req
, res
, function () {
49 db
.Pod
.loadByHost(req
.body
.host
, function (err
, pod
) {
51 logger
.error('Cannot load pod by host.', { error: err
})
55 // Pod with this host already exists
57 return res
.sendStatus(409)
65 // ---------------------------------------------------------------------------
67 module
.exports
= validatorsPod