diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2015-11-06 17:34:15 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2015-11-06 17:34:31 +0100 |
commit | f5a60a5138135a3412dfbcfd6e564f7aa47a55c2 (patch) | |
tree | 2516f410a33792f9112b4b4253929e5292908a3f /routes/api/v1/videos.js | |
parent | a6fa7ac141637a5026388157084c439f920c5ff1 (diff) | |
download | PeerTube-f5a60a5138135a3412dfbcfd6e564f7aa47a55c2.tar.gz PeerTube-f5a60a5138135a3412dfbcfd6e564f7aa47a55c2.tar.zst PeerTube-f5a60a5138135a3412dfbcfd6e564f7aa47a55c2.zip |
Add API versionning
Diffstat (limited to 'routes/api/v1/videos.js')
-rw-r--r-- | routes/api/v1/videos.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/routes/api/v1/videos.js b/routes/api/v1/videos.js new file mode 100644 index 000000000..246620ac6 --- /dev/null +++ b/routes/api/v1/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) return 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) return 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) return 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) return 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) return 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 | })() | ||