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/controllers/api/pods.js | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/controllers/api/pods.js')
-rw-r--r-- | server/controllers/api/pods.js | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/server/controllers/api/pods.js b/server/controllers/api/pods.js deleted file mode 100644 index ab5763cf6..000000000 --- a/server/controllers/api/pods.js +++ /dev/null | |||
@@ -1,109 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const express = require('express') | ||
4 | const waterfall = require('async/waterfall') | ||
5 | |||
6 | const db = require('../../initializers/database') | ||
7 | const constants = require('../../initializers/constants') | ||
8 | const logger = require('../../helpers/logger') | ||
9 | const peertubeCrypto = require('../../helpers/peertube-crypto') | ||
10 | const utils = require('../../helpers/utils') | ||
11 | const friends = require('../../lib/friends') | ||
12 | const middlewares = require('../../middlewares') | ||
13 | const admin = middlewares.admin | ||
14 | const oAuth = middlewares.oauth | ||
15 | const podsMiddleware = middlewares.pods | ||
16 | const validators = middlewares.validators.pods | ||
17 | |||
18 | const router = express.Router() | ||
19 | |||
20 | router.get('/', listPods) | ||
21 | router.post('/', | ||
22 | podsMiddleware.setBodyHostPort, // We need to modify the host before running the validator! | ||
23 | validators.podsAdd, | ||
24 | addPods | ||
25 | ) | ||
26 | router.post('/makefriends', | ||
27 | oAuth.authenticate, | ||
28 | admin.ensureIsAdmin, | ||
29 | validators.makeFriends, | ||
30 | podsMiddleware.setBodyHostsPort, | ||
31 | makeFriends | ||
32 | ) | ||
33 | router.get('/quitfriends', | ||
34 | oAuth.authenticate, | ||
35 | admin.ensureIsAdmin, | ||
36 | quitFriends | ||
37 | ) | ||
38 | |||
39 | // --------------------------------------------------------------------------- | ||
40 | |||
41 | module.exports = router | ||
42 | |||
43 | // --------------------------------------------------------------------------- | ||
44 | |||
45 | function addPods (req, res, next) { | ||
46 | const informations = req.body | ||
47 | |||
48 | waterfall([ | ||
49 | function addPod (callback) { | ||
50 | const pod = db.Pod.build(informations) | ||
51 | pod.save().asCallback(function (err, podCreated) { | ||
52 | // Be sure about the number of parameters for the callback | ||
53 | return callback(err, podCreated) | ||
54 | }) | ||
55 | }, | ||
56 | |||
57 | function sendMyVideos (podCreated, callback) { | ||
58 | friends.sendOwnedVideosToPod(podCreated.id) | ||
59 | |||
60 | callback(null) | ||
61 | }, | ||
62 | |||
63 | function fetchMyCertificate (callback) { | ||
64 | peertubeCrypto.getMyPublicCert(function (err, cert) { | ||
65 | if (err) { | ||
66 | logger.error('Cannot read cert file.') | ||
67 | return callback(err) | ||
68 | } | ||
69 | |||
70 | return callback(null, cert) | ||
71 | }) | ||
72 | } | ||
73 | ], function (err, cert) { | ||
74 | if (err) return next(err) | ||
75 | |||
76 | return res.json({ cert: cert, email: constants.CONFIG.ADMIN.EMAIL }) | ||
77 | }) | ||
78 | } | ||
79 | |||
80 | function listPods (req, res, next) { | ||
81 | db.Pod.list(function (err, podsList) { | ||
82 | if (err) return next(err) | ||
83 | |||
84 | res.json(utils.getFormatedObjects(podsList, podsList.length)) | ||
85 | }) | ||
86 | } | ||
87 | |||
88 | function makeFriends (req, res, next) { | ||
89 | const hosts = req.body.hosts | ||
90 | |||
91 | friends.makeFriends(hosts, function (err) { | ||
92 | if (err) { | ||
93 | logger.error('Could not make friends.', { error: err }) | ||
94 | return | ||
95 | } | ||
96 | |||
97 | logger.info('Made friends!') | ||
98 | }) | ||
99 | |||
100 | res.type('json').status(204).end() | ||
101 | } | ||
102 | |||
103 | function quitFriends (req, res, next) { | ||
104 | friends.quitFriends(function (err) { | ||
105 | if (err) return next(err) | ||
106 | |||
107 | res.type('json').status(204).end() | ||
108 | }) | ||
109 | } | ||