aboutsummaryrefslogtreecommitdiffhomepage
path: root/controllers/api/v1/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-02-07 11:23:23 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-02-07 11:23:23 +0100
commit9f10b2928df655c3672d9607e864e667d4bc903a (patch)
tree7743911b974b3a7fb0d4c7cec2a723942466b7f1 /controllers/api/v1/pods.js
parentd7c01e7793d813d804a3b5716d8288f9dcf71a16 (diff)
downloadPeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.tar.gz
PeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.tar.zst
PeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.zip
Remove useless anonymous functions of files
Diffstat (limited to 'controllers/api/v1/pods.js')
-rw-r--r--controllers/api/v1/pods.js136
1 files changed, 67 insertions, 69 deletions
diff --git a/controllers/api/v1/pods.js b/controllers/api/v1/pods.js
index 456f53dea..c93a86ee8 100644
--- a/controllers/api/v1/pods.js
+++ b/controllers/api/v1/pods.js
@@ -1,95 +1,93 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var express = require('express') 3var express = require('express')
5 var fs = require('fs') 4var fs = require('fs')
6 5
7 var logger = require('../../../helpers/logger') 6var logger = require('../../../helpers/logger')
8 var friends = require('../../../lib/friends') 7var friends = require('../../../lib/friends')
9 var middleware = require('../../../middlewares') 8var middleware = require('../../../middlewares')
10 var cacheMiddleware = middleware.cache 9var cacheMiddleware = middleware.cache
11 var peertubeCrypto = require('../../../helpers/peertubeCrypto') 10var peertubeCrypto = require('../../../helpers/peertubeCrypto')
12 var Pods = require('../../../models/pods') 11var Pods = require('../../../models/pods')
13 var reqValidator = middleware.reqValidators.pods 12var reqValidator = middleware.reqValidators.pods
14 var secureMiddleware = middleware.secure 13var secureMiddleware = middleware.secure
15 var secureRequest = middleware.reqValidators.remote.secureRequest 14var secureRequest = middleware.reqValidators.remote.secureRequest
16 var Videos = require('../../../models/videos') 15var Videos = require('../../../models/videos')
17 16
18 var router = express.Router() 17var router = express.Router()
19 18
20 router.get('/', cacheMiddleware.cache(false), listPods) 19router.get('/', cacheMiddleware.cache(false), listPods)
21 router.post('/', reqValidator.podsAdd, cacheMiddleware.cache(false), addPods) 20router.post('/', reqValidator.podsAdd, cacheMiddleware.cache(false), addPods)
22 router.get('/makefriends', reqValidator.makeFriends, cacheMiddleware.cache(false), makeFriends) 21router.get('/makefriends', reqValidator.makeFriends, cacheMiddleware.cache(false), makeFriends)
23 router.get('/quitfriends', cacheMiddleware.cache(false), quitFriends) 22router.get('/quitfriends', cacheMiddleware.cache(false), quitFriends)
24 // Post because this is a secured request 23// Post because this is a secured request
25 router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods) 24router.post('/remove', secureRequest, secureMiddleware.decryptBody, removePods)
26 25
27 // --------------------------------------------------------------------------- 26// ---------------------------------------------------------------------------
28 27
29 module.exports = router 28module.exports = router
30 29
31 // --------------------------------------------------------------------------- 30// ---------------------------------------------------------------------------
32 31
33 function addPods (req, res, next) { 32function addPods (req, res, next) {
34 var informations = req.body.data 33 var informations = req.body.data
35 Pods.add(informations, function (err) { 34 Pods.add(informations, function (err) {
36 if (err) return next(err) 35 if (err) return next(err)
37 36
38 Videos.addRemotes(informations.videos) 37 Videos.addRemotes(informations.videos)
39 38
40 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { 39 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) {
40 if (err) {
41 logger.error('Cannot read cert file.')
42 return next(err)
43 }
44
45 Videos.listOwned(function (err, videos_list) {
41 if (err) { 46 if (err) {
42 logger.error('Cannot read cert file.') 47 logger.error('Cannot get the list of owned videos.')
43 return next(err) 48 return next(err)
44 } 49 }
45 50
46 Videos.listOwned(function (err, videos_list) { 51 res.json({ cert: cert, videos: videos_list })
47 if (err) {
48 logger.error('Cannot get the list of owned videos.')
49 return next(err)
50 }
51
52 res.json({ cert: cert, videos: videos_list })
53 })
54 }) 52 })
55 }) 53 })
56 } 54 })
55}
57 56
58 function listPods (req, res, next) { 57function listPods (req, res, next) {
59 Pods.list(function (err, pods_list) { 58 Pods.list(function (err, pods_list) {
60 if (err) return next(err) 59 if (err) return next(err)
61 60
62 res.json(pods_list) 61 res.json(pods_list)
63 }) 62 })
64 } 63}
65 64
66 function makeFriends (req, res, next) { 65function makeFriends (req, res, next) {
67 friends.makeFriends(function (err) { 66 friends.makeFriends(function (err) {
68 if (err) return next(err) 67 if (err) return next(err)
69 68
70 res.sendStatus(204) 69 res.sendStatus(204)
71 }) 70 })
72 } 71}
73 72
74 function removePods (req, res, next) { 73function removePods (req, res, next) {
75 var url = req.body.signature.url 74 var url = req.body.signature.url
76 Pods.remove(url, function (err) { 75 Pods.remove(url, function (err) {
77 if (err) return next(err) 76 if (err) return next(err)
78 77
79 Videos.removeAllRemotesOf(url, function (err) { 78 Videos.removeAllRemotesOf(url, function (err) {
80 if (err) logger.error('Cannot remove all remote videos of %s.', url) 79 if (err) logger.error('Cannot remove all remote videos of %s.', url)
81 else logger.info('%s pod removed.', url) 80 else logger.info('%s pod removed.', url)
82 81
83 res.sendStatus(204) 82 res.sendStatus(204)
84 })
85 }) 83 })
86 } 84 })
85}
87 86
88 function quitFriends (req, res, next) { 87function quitFriends (req, res, next) {
89 friends.quitFriends(function (err) { 88 friends.quitFriends(function (err) {
90 if (err) return next(err) 89 if (err) return next(err)
91 90
92 res.sendStatus(204) 91 res.sendStatus(204)
93 }) 92 })
94 } 93}
95})()