diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/middlewares/validators/pods.js | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/middlewares/validators/pods.js')
-rw-r--r-- | server/middlewares/validators/pods.js | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/server/middlewares/validators/pods.js b/server/middlewares/validators/pods.js deleted file mode 100644 index 0bf4b1844..000000000 --- a/server/middlewares/validators/pods.js +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
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') | ||
9 | |||
10 | const validatorsPod = { | ||
11 | makeFriends, | ||
12 | podsAdd | ||
13 | } | ||
14 | |||
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.') | ||
19 | } | ||
20 | |||
21 | req.checkBody('hosts', 'Should have an array of unique hosts').isEachUniqueHostValid() | ||
22 | |||
23 | logger.debug('Checking makeFriends parameters', { parameters: req.body }) | ||
24 | |||
25 | checkErrors(req, res, function () { | ||
26 | friends.hasFriends(function (err, hasFriends) { | ||
27 | if (err) { | ||
28 | logger.error('Cannot know if we have friends.', { error: err }) | ||
29 | res.sendStatus(500) | ||
30 | } | ||
31 | |||
32 | if (hasFriends === true) { | ||
33 | // We need to quit our friends before make new ones | ||
34 | return res.sendStatus(409) | ||
35 | } | ||
36 | |||
37 | return next() | ||
38 | }) | ||
39 | }) | ||
40 | } | ||
41 | |||
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 }) | ||
47 | |||
48 | checkErrors(req, res, function () { | ||
49 | db.Pod.loadByHost(req.body.host, function (err, pod) { | ||
50 | if (err) { | ||
51 | logger.error('Cannot load pod by host.', { error: err }) | ||
52 | res.sendStatus(500) | ||
53 | } | ||
54 | |||
55 | // Pod with this host already exists | ||
56 | if (pod) { | ||
57 | return res.sendStatus(409) | ||
58 | } | ||
59 | |||
60 | return next() | ||
61 | }) | ||
62 | }) | ||
63 | } | ||
64 | |||
65 | // --------------------------------------------------------------------------- | ||
66 | |||
67 | module.exports = validatorsPod | ||