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