]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/middlewares/validators/pods.js
Server: fix video remoe validation
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / pods.js
... / ...
CommitLineData
1'use strict'
2
3const checkErrors = require('./utils').checkErrors
4const constants = require('../../initializers/constants')
5const friends = require('../../lib/friends')
6const logger = require('../../helpers/logger')
7const utils = require('../../helpers/utils')
8
9const validatorsPod = {
10 makeFriends,
11 podsAdd
12}
13
14function 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.')
18 }
19
20 req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid()
21
22 logger.debug('Checking makeFriends parameters', { parameters: req.body })
23
24 checkErrors(req, res, function () {
25 friends.hasFriends(function (err, hasFriends) {
26 if (err) {
27 logger.error('Cannot know if we have friends.', { error: err })
28 res.sendStatus(500)
29 }
30
31 if (hasFriends === true) {
32 // We need to quit our friends before make new ones
33 res.sendStatus(409)
34 } else {
35 return next()
36 }
37 })
38 })
39}
40
41function podsAdd (req, res, next) {
42 req.checkBody('host', 'Should have an host').notEmpty().isURL()
43 req.checkBody('publicKey', 'Should have a public key').notEmpty()
44
45 // TODO: check we don't have it already
46
47 logger.debug('Checking podsAdd parameters', { parameters: req.body })
48
49 checkErrors(req, res, next)
50}
51
52// ---------------------------------------------------------------------------
53
54module.exports = validatorsPod