aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/controllers/api/pods.js
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-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.js109
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
3const express = require('express')
4const waterfall = require('async/waterfall')
5
6const db = require('../../initializers/database')
7const constants = require('../../initializers/constants')
8const logger = require('../../helpers/logger')
9const peertubeCrypto = require('../../helpers/peertube-crypto')
10const utils = require('../../helpers/utils')
11const friends = require('../../lib/friends')
12const middlewares = require('../../middlewares')
13const admin = middlewares.admin
14const oAuth = middlewares.oauth
15const podsMiddleware = middlewares.pods
16const validators = middlewares.validators.pods
17
18const router = express.Router()
19
20router.get('/', listPods)
21router.post('/',
22 podsMiddleware.setBodyHostPort, // We need to modify the host before running the validator!
23 validators.podsAdd,
24 addPods
25)
26router.post('/makefriends',
27 oAuth.authenticate,
28 admin.ensureIsAdmin,
29 validators.makeFriends,
30 podsMiddleware.setBodyHostsPort,
31 makeFriends
32)
33router.get('/quitfriends',
34 oAuth.authenticate,
35 admin.ensureIsAdmin,
36 quitFriends
37)
38
39// ---------------------------------------------------------------------------
40
41module.exports = router
42
43// ---------------------------------------------------------------------------
44
45function 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
80function 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
88function 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
103function 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}