aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-24 17:05:32 +0200
committerChocobozzz <me@florianbigard.com>2018-04-24 17:12:57 +0200
commit48dce1c90dff4e90a4bcffefaecf157336cf904b (patch)
tree478de23812d0bfd93f47e9ad6ad8888c9edcc235 /server/middlewares
parent82e392f8a42a19815e932dd386e96e61ebe6d191 (diff)
downloadPeerTube-48dce1c90dff4e90a4bcffefaecf157336cf904b.tar.gz
PeerTube-48dce1c90dff4e90a4bcffefaecf157336cf904b.tar.zst
PeerTube-48dce1c90dff4e90a4bcffefaecf157336cf904b.zip
Update video channel routes
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/follows.ts2
-rw-r--r--server/middlewares/validators/video-channels.ts8
2 files changed, 9 insertions, 1 deletions
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 991a2e175..bdf39eb9c 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -16,7 +16,7 @@ const followValidator = [
16 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { 16 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') {
17 return res.status(400) 17 return res.status(400)
18 .json({ 18 .json({
19 error: 'Cannot follow non HTTPS web server.' 19 error: 'Cannot follow on a non HTTPS web server.'
20 }) 20 })
21 .end() 21 .end()
22 } 22 }
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index fe42105e8..e3a11a41b 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -26,6 +26,7 @@ const listVideoAccountChannelsValidator = [
26] 26]
27 27
28const videoChannelsAddValidator = [ 28const videoChannelsAddValidator = [
29 param('accountId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
29 body('name').custom(isVideoChannelNameValid).withMessage('Should have a valid name'), 30 body('name').custom(isVideoChannelNameValid).withMessage('Should have a valid name'),
30 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 31 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
31 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), 32 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@@ -41,6 +42,7 @@ const videoChannelsAddValidator = [
41 42
42const videoChannelsUpdateValidator = [ 43const videoChannelsUpdateValidator = [
43 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 44 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
45 param('accountId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
44 body('name').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid name'), 46 body('name').optional().custom(isVideoChannelNameValid).withMessage('Should have a valid name'),
45 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), 47 body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
46 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), 48 body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
@@ -49,6 +51,7 @@ const videoChannelsUpdateValidator = [
49 logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body }) 51 logger.debug('Checking videoChannelsUpdate parameters', { parameters: req.body })
50 52
51 if (areValidationErrors(req, res)) return 53 if (areValidationErrors(req, res)) return
54 if (!await isAccountIdExist(req.params.accountId, res)) return
52 if (!await isVideoChannelExist(req.params.id, res)) return 55 if (!await isVideoChannelExist(req.params.id, res)) return
53 56
54 // We need to make additional checks 57 // We need to make additional checks
@@ -70,11 +73,13 @@ const videoChannelsUpdateValidator = [
70 73
71const videoChannelsRemoveValidator = [ 74const videoChannelsRemoveValidator = [
72 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 75 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
76 param('accountId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
73 77
74 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 78 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
75 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params }) 79 logger.debug('Checking videoChannelsRemove parameters', { parameters: req.params })
76 80
77 if (areValidationErrors(req, res)) return 81 if (areValidationErrors(req, res)) return
82 if (!await isAccountIdExist(req.params.accountId, res)) return
78 if (!await isVideoChannelExist(req.params.id, res)) return 83 if (!await isVideoChannelExist(req.params.id, res)) return
79 84
80 // Check if the user who did the request is able to delete the video 85 // Check if the user who did the request is able to delete the video
@@ -87,11 +92,14 @@ const videoChannelsRemoveValidator = [
87 92
88const videoChannelsGetValidator = [ 93const videoChannelsGetValidator = [
89 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 94 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
95 param('accountId').optional().custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid account id'),
90 96
91 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 97 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
92 logger.debug('Checking videoChannelsGet parameters', { parameters: req.params }) 98 logger.debug('Checking videoChannelsGet parameters', { parameters: req.params })
93 99
94 if (areValidationErrors(req, res)) return 100 if (areValidationErrors(req, res)) return
101 // On some routes, accountId is optional (for example in the ActivityPub route)
102 if (req.params.accountId && !await isAccountIdExist(req.params.accountId, res)) return
95 if (!await isVideoChannelExist(req.params.id, res)) return 103 if (!await isVideoChannelExist(req.params.id, res)) return
96 104
97 return next() 105 return next()