diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-01-30 17:05:22 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-01-30 17:05:22 +0100 |
commit | cda021079ff455cc0fd0eb95a5395fa808ab63d1 (patch) | |
tree | 056716de7460462b74b861051a5e9da6e2633fce /routes | |
parent | 86435b9baedfe300a28ea4545511c1b50d4119f6 (diff) | |
download | PeerTube-cda021079ff455cc0fd0eb95a5395fa808ab63d1.tar.gz PeerTube-cda021079ff455cc0fd0eb95a5395fa808ab63d1.tar.zst PeerTube-cda021079ff455cc0fd0eb95a5395fa808ab63d1.zip |
New directory organization
Diffstat (limited to 'routes')
-rw-r--r-- | routes/api/v1/index.js | 12 | ||||
-rw-r--r-- | routes/api/v1/pods.js | 69 | ||||
-rw-r--r-- | routes/api/v1/remoteVideos.js | 33 | ||||
-rw-r--r-- | routes/api/v1/videos.js | 88 | ||||
-rw-r--r-- | routes/index.js | 12 | ||||
-rw-r--r-- | routes/views.js | 24 |
6 files changed, 0 insertions, 238 deletions
diff --git a/routes/api/v1/index.js b/routes/api/v1/index.js deleted file mode 100644 index f5504ad85..000000000 --- a/routes/api/v1/index.js +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var express = require('express') | ||
5 | var router = express.Router() | ||
6 | |||
7 | router.use('/videos', require('./videos')) | ||
8 | router.use('/remotevideos', require('./remoteVideos')) | ||
9 | router.use('/pods', require('./pods')) | ||
10 | |||
11 | module.exports = router | ||
12 | })() | ||
diff --git a/routes/api/v1/pods.js b/routes/api/v1/pods.js deleted file mode 100644 index 2430b0d7e..000000000 --- a/routes/api/v1/pods.js +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var express = require('express') | ||
5 | var router = express.Router() | ||
6 | var middleware = require('../../../middlewares') | ||
7 | var miscMiddleware = middleware.misc | ||
8 | var reqValidator = middleware.reqValidators.pods | ||
9 | var secureRequest = middleware.reqValidators.remote.secureRequest | ||
10 | var pods = require('../../../src/pods') | ||
11 | |||
12 | function listPods (req, res, next) { | ||
13 | pods.list(function (err, pods_list) { | ||
14 | if (err) return next(err) | ||
15 | |||
16 | res.json(pods_list) | ||
17 | }) | ||
18 | } | ||
19 | |||
20 | function addPods (req, res, next) { | ||
21 | pods.add(req.body.data, function (err, json) { | ||
22 | if (err) return next(err) | ||
23 | |||
24 | res.json(json) | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | function removePods (req, res, next) { | ||
29 | pods.remove(req.body.signature.url, function (err) { | ||
30 | if (err) return next(err) | ||
31 | |||
32 | res.sendStatus(204) | ||
33 | }) | ||
34 | } | ||
35 | |||
36 | function makeFriends (req, res, next) { | ||
37 | pods.hasFriends(function (err, has_friends) { | ||
38 | if (err) return next(err) | ||
39 | |||
40 | if (has_friends === true) { | ||
41 | // We need to quit our friends before make new ones | ||
42 | res.sendStatus(409) | ||
43 | } else { | ||
44 | pods.makeFriends(function (err) { | ||
45 | if (err) return next(err) | ||
46 | |||
47 | res.sendStatus(204) | ||
48 | }) | ||
49 | } | ||
50 | }) | ||
51 | } | ||
52 | |||
53 | function quitFriends (req, res, next) { | ||
54 | pods.quitFriends(function (err) { | ||
55 | if (err) return next(err) | ||
56 | |||
57 | res.sendStatus(204) | ||
58 | }) | ||
59 | } | ||
60 | |||
61 | router.get('/', miscMiddleware.cache(false), listPods) | ||
62 | router.get('/makefriends', miscMiddleware.cache(false), makeFriends) | ||
63 | router.get('/quitfriends', miscMiddleware.cache(false), quitFriends) | ||
64 | router.post('/', reqValidator.podsAdd, miscMiddleware.cache(false), addPods) | ||
65 | // Post because this is a secured request | ||
66 | router.post('/remove', secureRequest, miscMiddleware.decryptBody, removePods) | ||
67 | |||
68 | module.exports = router | ||
69 | })() | ||
diff --git a/routes/api/v1/remoteVideos.js b/routes/api/v1/remoteVideos.js deleted file mode 100644 index 6ba6ce17b..000000000 --- a/routes/api/v1/remoteVideos.js +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var express = require('express') | ||
5 | var router = express.Router() | ||
6 | var pluck = require('lodash-node/compat/collection/pluck') | ||
7 | |||
8 | var middleware = require('../../../middlewares') | ||
9 | var miscMiddleware = middleware.misc | ||
10 | var reqValidator = middleware.reqValidators.remote | ||
11 | var videos = require('../../../src/videos') | ||
12 | |||
13 | function addRemoteVideos (req, res, next) { | ||
14 | videos.addRemotes(req.body.data, function (err, videos) { | ||
15 | if (err) return next(err) | ||
16 | |||
17 | res.json(videos) | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | function removeRemoteVideo (req, res, next) { | ||
22 | videos.removeRemotes(req.body.signature.url, pluck(req.body.data, 'magnetUri'), function (err) { | ||
23 | if (err) return next(err) | ||
24 | |||
25 | res.sendStatus(204) | ||
26 | }) | ||
27 | } | ||
28 | |||
29 | router.post('/add', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosAdd, miscMiddleware.cache(false), addRemoteVideos) | ||
30 | router.post('/remove', reqValidator.secureRequest, miscMiddleware.decryptBody, reqValidator.remoteVideosRemove, miscMiddleware.cache(false), removeRemoteVideo) | ||
31 | |||
32 | module.exports = router | ||
33 | })() | ||
diff --git a/routes/api/v1/videos.js b/routes/api/v1/videos.js deleted file mode 100644 index 95c1dffc7..000000000 --- a/routes/api/v1/videos.js +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var express = require('express') | ||
5 | var config = require('config') | ||
6 | var crypto = require('crypto') | ||
7 | var multer = require('multer') | ||
8 | var router = express.Router() | ||
9 | |||
10 | var middleware = require('../../../middlewares') | ||
11 | var miscMiddleware = middleware.misc | ||
12 | var reqValidator = middleware.reqValidators.videos | ||
13 | var videos = require('../../../src/videos') | ||
14 | |||
15 | var uploads = config.get('storage.uploads') | ||
16 | |||
17 | function listVideos (req, res, next) { | ||
18 | videos.list(function (err, videos_list) { | ||
19 | if (err) return next(err) | ||
20 | |||
21 | res.json(videos_list) | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | function searchVideos (req, res, next) { | ||
26 | videos.search(req.params.name, function (err, videos_list) { | ||
27 | if (err) return next(err) | ||
28 | |||
29 | res.json(videos_list) | ||
30 | }) | ||
31 | } | ||
32 | |||
33 | function addVideos (req, res, next) { | ||
34 | videos.add({ video: req.files.input_video[0], data: req.body }, function (err) { | ||
35 | if (err) return next(err) | ||
36 | |||
37 | // TODO : include Location of the new video | ||
38 | res.sendStatus(201) | ||
39 | }) | ||
40 | } | ||
41 | |||
42 | function getVideos (req, res, next) { | ||
43 | videos.get(req.params.id, function (err, video) { | ||
44 | if (err) return next(err) | ||
45 | |||
46 | if (video === null) { | ||
47 | return res.sendStatus(404) | ||
48 | } | ||
49 | |||
50 | res.json(video) | ||
51 | }) | ||
52 | } | ||
53 | |||
54 | function removeVideo (req, res, next) { | ||
55 | videos.remove(req.params.id, function (err) { | ||
56 | if (err) return next(err) | ||
57 | |||
58 | res.sendStatus(204) | ||
59 | }) | ||
60 | } | ||
61 | |||
62 | // multer configuration | ||
63 | var storage = multer.diskStorage({ | ||
64 | destination: function (req, file, cb) { | ||
65 | cb(null, uploads) | ||
66 | }, | ||
67 | |||
68 | filename: function (req, file, cb) { | ||
69 | var extension = '' | ||
70 | if (file.mimetype === 'video/webm') extension = 'webm' | ||
71 | else if (file.mimetype === 'video/mp4') extension = 'mp4' | ||
72 | else if (file.mimetype === 'video/ogg') extension = 'ogv' | ||
73 | crypto.pseudoRandomBytes(16, function (err, raw) { | ||
74 | var fieldname = err ? undefined : raw.toString('hex') | ||
75 | cb(null, fieldname + '.' + extension) | ||
76 | }) | ||
77 | } | ||
78 | }) | ||
79 | var reqFiles = multer({ storage: storage }).fields([{ name: 'input_video', maxCount: 1 }]) | ||
80 | |||
81 | router.get('/', miscMiddleware.cache(false), listVideos) | ||
82 | router.post('/', reqFiles, reqValidator.videosAdd, miscMiddleware.cache(false), addVideos) | ||
83 | router.get('/search/:name', reqValidator.videosSearch, miscMiddleware.cache(false), searchVideos) | ||
84 | router.get('/:id', reqValidator.videosGet, miscMiddleware.cache(false), getVideos) | ||
85 | router.delete('/:id', reqValidator.videosRemove, miscMiddleware.cache(false), removeVideo) | ||
86 | |||
87 | module.exports = router | ||
88 | })() | ||
diff --git a/routes/index.js b/routes/index.js deleted file mode 100644 index f45aa7ba5..000000000 --- a/routes/index.js +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var constants = require('../src/constants') | ||
5 | |||
6 | var routes = { | ||
7 | api: require('./api/' + constants.API_VERSION), | ||
8 | views: require('./views') | ||
9 | } | ||
10 | |||
11 | module.exports = routes | ||
12 | })() | ||
diff --git a/routes/views.js b/routes/views.js deleted file mode 100644 index ebd97380e..000000000 --- a/routes/views.js +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | function getPartial (req, res) { | ||
5 | var directory = req.params.directory | ||
6 | var name = req.params.name | ||
7 | |||
8 | res.render('partials/' + directory + '/' + name) | ||
9 | } | ||
10 | |||
11 | function getIndex (req, res) { | ||
12 | res.render('index') | ||
13 | } | ||
14 | |||
15 | var express = require('express') | ||
16 | var middleware = require('../middlewares').misc | ||
17 | |||
18 | var router = express.Router() | ||
19 | |||
20 | router.get('/partials/:directory/:name', middleware.cache(), getPartial) | ||
21 | router.get(/^\/(index)?$/, middleware.cache(), getIndex) | ||
22 | |||
23 | module.exports = router | ||
24 | })() | ||