]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/pods.js
3 const express
= require('express')
4 const waterfall
= require('async/waterfall')
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
18 const router
= express
.Router()
20 router
.get('/', listPods
)
22 podsMiddleware
.setBodyHostPort
, // We need to modify the host before running the validator!
26 router
.post('/makefriends',
29 validators
.makeFriends
,
30 podsMiddleware
.setBodyHostsPort
,
33 router
.get('/quitfriends',
39 // ---------------------------------------------------------------------------
41 module
.exports
= router
43 // ---------------------------------------------------------------------------
45 function addPods (req
, res
, next
) {
46 const informations
= req
.body
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
)
57 function sendMyVideos (podCreated
, callback
) {
58 friends
.sendOwnedVideosToPod(podCreated
.id
)
63 function fetchMyCertificate (callback
) {
64 peertubeCrypto
.getMyPublicCert(function (err
, cert
) {
66 logger
.error('Cannot read cert file.')
70 return callback(null, cert
)
73 ], function (err
, cert
) {
74 if (err
) return next(err
)
76 return res
.json({ cert: cert
, email: constants
.CONFIG
.ADMIN
.EMAIL
})
80 function listPods (req
, res
, next
) {
81 db
.Pod
.list(function (err
, podsList
) {
82 if (err
) return next(err
)
84 res
.json(utils
.getFormatedObjects(podsList
, podsList
.length
))
88 function makeFriends (req
, res
, next
) {
89 const hosts
= req
.body
.hosts
91 friends
.makeFriends(hosts
, function (err
) {
93 logger
.error('Could not make friends.', { error: err
})
97 logger
.info('Made friends!')
100 res
.type('json').status(204).end()
103 function quitFriends (req
, res
, next
) {
104 friends
.quitFriends(function (err
) {
105 if (err
) return next(err
)
107 res
.type('json').status(204).end()