aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/video-channels.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-27 14:44:51 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch)
treee1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/middlewares/validators/video-channels.ts
parent74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff)
downloadPeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.gz
PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.tar.zst
PeerTube-4e50b6a1c9a3eb261e04ede73241648e6edf21d6.zip
Add shares forward and collection on videos/video channels
Diffstat (limited to 'server/middlewares/validators/video-channels.ts')
-rw-r--r--server/middlewares/validators/video-channels.ts41
1 files changed, 35 insertions, 6 deletions
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index c6fd3b59d..f30fbf0dc 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -1,13 +1,19 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../shared' 3import { UserRight } from '../../../shared'
4import { checkVideoAccountExists } from '../../helpers/custom-validators/accounts' 4import { checkAccountIdExists } from '../../helpers/custom-validators/accounts'
5import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' 5import { isIdValid } from '../../helpers/custom-validators/misc'
6import { checkVideoChannelExists, isIdOrUUIDValid } from '../../helpers/index' 6import {
7 checkVideoChannelExists,
8 isVideoChannelDescriptionValid,
9 isVideoChannelExistsPromise,
10 isVideoChannelNameValid
11} from '../../helpers/custom-validators/video-channels'
12import { isIdOrUUIDValid } from '../../helpers/index'
7import { logger } from '../../helpers/logger' 13import { logger } from '../../helpers/logger'
8import { database as db } from '../../initializers' 14import { database as db } from '../../initializers'
9import { UserInstance } from '../../models' 15import { UserInstance } from '../../models'
10import { checkErrors } from './utils' 16import { areValidationErrors, checkErrors } from './utils'
11 17
12const listVideoAccountChannelsValidator = [ 18const listVideoAccountChannelsValidator = [
13 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), 19 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
@@ -16,7 +22,7 @@ const listVideoAccountChannelsValidator = [
16 logger.debug('Checking listVideoAccountChannelsValidator parameters', { parameters: req.body }) 22 logger.debug('Checking listVideoAccountChannelsValidator parameters', { parameters: req.body })
17 23
18 checkErrors(req, res, () => { 24 checkErrors(req, res, () => {
19 checkVideoAccountExists(req.params.accountId, res, next) 25 checkAccountIdExists(req.params.accountId, res, next)
20 }) 26 })
21 } 27 }
22] 28]
@@ -90,6 +96,28 @@ const videoChannelsGetValidator = [
90 } 96 }
91] 97]
92 98
99const videoChannelsShareValidator = [
100 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
101 param('accountId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid account id'),
102
103 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
104 logger.debug('Checking videoChannelShare parameters', { parameters: req.params })
105
106 if (areValidationErrors(req, res)) return
107 if (!await isVideoChannelExistsPromise(req.params.id, res)) return
108
109 const share = await db.VideoChannelShare.load(res.locals.video.id, req.params.accountId)
110 if (!share) {
111 return res.status(404)
112 .end()
113 }
114
115 res.locals.videoChannelShare = share
116
117 return next()
118 }
119]
120
93// --------------------------------------------------------------------------- 121// ---------------------------------------------------------------------------
94 122
95export { 123export {
@@ -97,7 +125,8 @@ export {
97 videoChannelsAddValidator, 125 videoChannelsAddValidator,
98 videoChannelsUpdateValidator, 126 videoChannelsUpdateValidator,
99 videoChannelsRemoveValidator, 127 videoChannelsRemoveValidator,
100 videoChannelsGetValidator 128 videoChannelsGetValidator,
129 videoChannelsShareValidator
101} 130}
102 131
103// --------------------------------------------------------------------------- 132// ---------------------------------------------------------------------------