aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2015-06-09 17:41:40 +0200
committerChocobozzz <florian.bigard@gmail.com>2015-10-29 23:14:54 +0100
commit8c308c2bf7f658945d80be9d5880361238635f5b (patch)
tree2130ae60af58e59dab3df07a5d5cdd5174f91ae8 /routes/api
parent8cb4b4e00ee57eb98dfe1455b6d2de36fc561797 (diff)
downloadPeerTube-8c308c2bf7f658945d80be9d5880361238635f5b.tar.gz
PeerTube-8c308c2bf7f658945d80be9d5880361238635f5b.tar.zst
PeerTube-8c308c2bf7f658945d80be9d5880361238635f5b.zip
Spawn
Diffstat (limited to 'routes/api')
-rw-r--r--routes/api/index.js10
-rw-r--r--routes/api/pods.js38
-rw-r--r--routes/api/remoteVideos.js29
-rw-r--r--routes/api/videos.js61
4 files changed, 138 insertions, 0 deletions
diff --git a/routes/api/index.js b/routes/api/index.js
new file mode 100644
index 000000000..9a4ec8438
--- /dev/null
+++ b/routes/api/index.js
@@ -0,0 +1,10 @@
1;(function () {
2 'use strict'
3
4 var api = {}
5 api.videos = require('./videos')
6 api.remoteVideos = require('./remoteVideos')
7 api.pods = require('./pods')
8
9 module.exports = api
10})()
diff --git a/routes/api/pods.js b/routes/api/pods.js
new file mode 100644
index 000000000..3f9e85052
--- /dev/null
+++ b/routes/api/pods.js
@@ -0,0 +1,38 @@
1;(function () {
2 'use strict'
3
4 var express = require('express')
5 var router = express.Router()
6 var middleware = require('../../middlewares')
7 var pods = require('../../src/pods')
8
9 function listPods (req, res, next) {
10 pods.list(function (err, pods_list) {
11 if (err) next(err)
12
13 res.json(pods_list)
14 })
15 }
16
17 function addPods (req, res, next) {
18 pods.add(req.body.data, function (err, json) {
19 if (err) next(err)
20
21 res.json(json)
22 })
23 }
24
25 function makeFriends (req, res, next) {
26 pods.makeFriends(function (err) {
27 if (err) next(err)
28
29 res.sendStatus(204)
30 })
31 }
32
33 router.get('/', middleware.cache(false), listPods)
34 router.get('/makefriends', middleware.cache(false), makeFriends)
35 router.post('/', middleware.cache(false), addPods)
36
37 module.exports = router
38})()
diff --git a/routes/api/remoteVideos.js b/routes/api/remoteVideos.js
new file mode 100644
index 000000000..eed586d23
--- /dev/null
+++ b/routes/api/remoteVideos.js
@@ -0,0 +1,29 @@
1;(function () {
2 'use strict'
3
4 var express = require('express')
5 var router = express.Router()
6 var middleware = require('../../middlewares')
7 var videos = require('../../src/videos')
8
9 function addRemoteVideos (req, res, next) {
10 videos.addRemote(req.body.data, function (err, video) {
11 if (err) next(err)
12
13 res.json(video)
14 })
15 }
16
17 function removeRemoteVideo (req, res, next) {
18 videos.removeRemote(req.body.signature.url, req.body.data.magnetUri, function (err) {
19 if (err) next(err)
20
21 res.status(204)
22 })
23 }
24
25 router.post('/add', middleware.cache(false), middleware.decryptBody, addRemoteVideos)
26 router.post('/remove', middleware.cache(false), middleware.decryptBody, removeRemoteVideo)
27
28 module.exports = router
29})()
diff --git a/routes/api/videos.js b/routes/api/videos.js
new file mode 100644
index 000000000..c38d6d42c
--- /dev/null
+++ b/routes/api/videos.js
@@ -0,0 +1,61 @@
1;(function () {
2 'use strict'
3
4 var express = require('express')
5 var router = express.Router()
6 var middleware = require('../../middlewares')
7 var videos = require('../../src/videos')
8
9 function listVideos (req, res, next) {
10 videos.list(function (err, videos_list) {
11 if (err) next(err)
12
13 res.json(videos_list)
14 })
15 }
16
17 function searchVideos (req, res, next) {
18 videos.search(req.params.name, function (err, videos_list) {
19 if (err) next(err)
20
21 res.json(videos_list)
22 })
23 }
24
25 function addVideos (req, res, next) {
26 videos.add({ video: req.files.input_video, data: req.body }, function (err) {
27 if (err) next(err)
28
29 // TODO : include Location of the new video
30 res.sendStatus(201)
31 })
32 }
33
34 function getVideos (req, res, next) {
35 videos.get(req.params.id, function (err, video) {
36 if (err) next(err)
37
38 if (video === null) {
39 return res.sendStatus(404)
40 }
41
42 res.json(video)
43 })
44 }
45
46 function removeVideo (req, res, next) {
47 videos.remove(req.params.id, function (err) {
48 if (err) next(err)
49
50 res.sendStatus(204)
51 })
52 }
53
54 router.get('/', middleware.cache(false), listVideos)
55 router.post('/', middleware.cache(false), addVideos)
56 router.get('/search/:name', middleware.cache(false), searchVideos)
57 router.get('/:id', middleware.cache(false), getVideos)
58 router.delete('/:id', middleware.cache(false), removeVideo)
59
60 module.exports = router
61})()