]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/pods.js
Server: Fix video propagation with transcoding enabled
[github/Chocobozzz/PeerTube.git] / server / controllers / api / pods.js
index 79f3f9d8d7fb2f0c1eee357be4873ddc974ab585..ab5763cf6a1f84f96decc08e6f8ec77cae648c53 100644 (file)
@@ -4,22 +4,23 @@ const express = require('express')
 const waterfall = require('async/waterfall')
 
 const db = require('../../initializers/database')
+const constants = require('../../initializers/constants')
 const logger = require('../../helpers/logger')
+const peertubeCrypto = require('../../helpers/peertube-crypto')
+const utils = require('../../helpers/utils')
 const friends = require('../../lib/friends')
 const middlewares = require('../../middlewares')
 const admin = middlewares.admin
 const oAuth = middlewares.oauth
 const podsMiddleware = middlewares.pods
-const checkSignature = middlewares.secure.checkSignature
 const validators = middlewares.validators.pods
-const signatureValidator = middlewares.validators.remote.signature
 
 const router = express.Router()
 
 router.get('/', listPods)
 router.post('/',
+  podsMiddleware.setBodyHostPort, // We need to modify the host before running the validator!
   validators.podsAdd,
-  podsMiddleware.setBodyHostPort,
   addPods
 )
 router.post('/makefriends',
@@ -34,12 +35,6 @@ router.get('/quitfriends',
   admin.ensureIsAdmin,
   quitFriends
 )
-// Post because this is a secured request
-router.post('/remove',
-  signatureValidator,
-  checkSignature,
-  removePods
-)
 
 // ---------------------------------------------------------------------------
 
@@ -66,7 +61,7 @@ function addPods (req, res, next) {
     },
 
     function fetchMyCertificate (callback) {
-      friends.getMyCertificate(function (err, cert) {
+      peertubeCrypto.getMyPublicCert(function (err, cert) {
         if (err) {
           logger.error('Cannot read cert file.')
           return callback(err)
@@ -78,7 +73,7 @@ function addPods (req, res, next) {
   ], function (err, cert) {
     if (err) return next(err)
 
-    return res.json({ cert: cert })
+    return res.json({ cert: cert, email: constants.CONFIG.ADMIN.EMAIL })
   })
 }
 
@@ -86,7 +81,7 @@ function listPods (req, res, next) {
   db.Pod.list(function (err, podsList) {
     if (err) return next(err)
 
-    res.json(getFormatedPods(podsList))
+    res.json(utils.getFormatedObjects(podsList, podsList.length))
   })
 }
 
@@ -105,24 +100,6 @@ function makeFriends (req, res, next) {
   res.type('json').status(204).end()
 }
 
-function removePods (req, res, next) {
-  const host = req.body.signature.host
-
-  waterfall([
-    function loadPod (callback) {
-      db.Pod.loadByHost(host, callback)
-    },
-
-    function removePod (pod, callback) {
-      pod.destroy().asCallback(callback)
-    }
-  ], function (err) {
-    if (err) return next(err)
-
-    return res.type('json').status(204).end()
-  })
-}
-
 function quitFriends (req, res, next) {
   friends.quitFriends(function (err) {
     if (err) return next(err)
@@ -130,15 +107,3 @@ function quitFriends (req, res, next) {
     res.type('json').status(204).end()
   })
 }
-
-// ---------------------------------------------------------------------------
-
-function getFormatedPods (pods) {
-  const formatedPods = []
-
-  pods.forEach(function (pod) {
-    formatedPods.push(pod.toFormatedJSON())
-  })
-
-  return formatedPods
-}