aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-04-14 22:06:11 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-04-14 22:06:11 +0200
commit0c1cbbfe29d91c95f9c574b57adf067654b8b5b4 (patch)
treeb61e48caedea8881cbfd1159295f6c311b35be90 /server/controllers/api/v1
parentc9bf7d30bd688e84b12dca03029dde6e9645a997 (diff)
downloadPeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.tar.gz
PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.tar.zst
PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.zip
Add authentications for routes that need it and adapts the tests
Diffstat (limited to 'server/controllers/api/v1')
-rw-r--r--server/controllers/api/v1/users.js7
-rw-r--r--server/controllers/api/v1/videos.js11
2 files changed, 10 insertions, 8 deletions
diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js
index acb860c66..f45b47077 100644
--- a/server/controllers/api/v1/users.js
+++ b/server/controllers/api/v1/users.js
@@ -1,15 +1,14 @@
1'use strict' 1'use strict'
2 2
3var express = require('express') 3const express = require('express')
4var oAuth2 = require('../../../middlewares/oauth2') 4const oAuth2 = require('../../../middlewares/oauth2')
5 5
6const middleware = require('../../../middlewares') 6const middleware = require('../../../middlewares')
7const cacheMiddleware = middleware.cache 7const cacheMiddleware = middleware.cache
8 8
9const router = express.Router() 9const router = express.Router()
10 10
11router.post('/token', cacheMiddleware.cache(false), oAuth2.token(), success) 11router.post('/token', cacheMiddleware.cache(false), oAuth2.token, success)
12router.get('/authenticate', cacheMiddleware.cache(false), oAuth2.authenticate(), success)
13 12
14// --------------------------------------------------------------------------- 13// ---------------------------------------------------------------------------
15 14
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index 97d3e6b5a..d25ca95f7 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -8,6 +8,7 @@ const multer = require('multer')
8const logger = require('../../../helpers/logger') 8const logger = require('../../../helpers/logger')
9const friends = require('../../../lib/friends') 9const friends = require('../../../lib/friends')
10const middleware = require('../../../middlewares') 10const middleware = require('../../../middlewares')
11const oAuth2 = require('../../../middlewares/oauth2')
11const cacheMiddleware = middleware.cache 12const cacheMiddleware = middleware.cache
12const reqValidator = middleware.reqValidators.videos 13const reqValidator = middleware.reqValidators.videos
13const Videos = require('../../../models/videos') // model 14const Videos = require('../../../models/videos') // model
@@ -38,9 +39,9 @@ const storage = multer.diskStorage({
38const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) 39const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
39 40
40router.get('/', cacheMiddleware.cache(false), listVideos) 41router.get('/', cacheMiddleware.cache(false), listVideos)
41router.post('/', reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo) 42router.post('/', oAuth2.authenticate, reqFiles, reqValidator.videosAdd, cacheMiddleware.cache(false), addVideo)
42router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos) 43router.get('/:id', reqValidator.videosGet, cacheMiddleware.cache(false), getVideos)
43router.delete('/:id', reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo) 44router.delete('/:id', oAuth2.authenticate, reqValidator.videosRemove, cacheMiddleware.cache(false), removeVideo)
44router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos) 45router.get('/search/:name', reqValidator.videosSearch, cacheMiddleware.cache(false), searchVideos)
45 46
46// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
@@ -63,7 +64,8 @@ function addVideo (req, res, next) {
63 name: video_infos.name, 64 name: video_infos.name,
64 namePath: video_file.filename, 65 namePath: video_file.filename,
65 description: video_infos.description, 66 description: video_infos.description,
66 magnetUri: torrent.magnetURI 67 magnetUri: torrent.magnetURI,
68 author: res.locals.oauth.token.user.username
67 } 69 }
68 70
69 Videos.add(video_data, function (err) { 71 Videos.add(video_data, function (err) {
@@ -141,7 +143,8 @@ function getFormatedVideo (video_obj) {
141 description: video_obj.description, 143 description: video_obj.description,
142 podUrl: video_obj.podUrl, 144 podUrl: video_obj.podUrl,
143 isLocal: videos.getVideoState(video_obj).owned, 145 isLocal: videos.getVideoState(video_obj).owned,
144 magnetUri: video_obj.magnetUri 146 magnetUri: video_obj.magnetUri,
147 author: video_obj.author
145 } 148 }
146 149
147 return formated_video 150 return formated_video