diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 14:44:51 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 4e50b6a1c9a3eb261e04ede73241648e6edf21d6 (patch) | |
tree | e1c6c121d561ffc1cf2996daec03a1e7f27f0a25 /server/middlewares/validators/video-channels.ts | |
parent | 74bb2cb8348d6794ed3a0e2ec94c8c9abdde82cf (diff) | |
download | PeerTube-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.ts | 41 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { body, param } from 'express-validator/check' | 2 | import { body, param } from 'express-validator/check' |
3 | import { UserRight } from '../../../shared' | 3 | import { UserRight } from '../../../shared' |
4 | import { checkVideoAccountExists } from '../../helpers/custom-validators/accounts' | 4 | import { checkAccountIdExists } from '../../helpers/custom-validators/accounts' |
5 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' | 5 | import { isIdValid } from '../../helpers/custom-validators/misc' |
6 | import { checkVideoChannelExists, isIdOrUUIDValid } from '../../helpers/index' | 6 | import { |
7 | checkVideoChannelExists, | ||
8 | isVideoChannelDescriptionValid, | ||
9 | isVideoChannelExistsPromise, | ||
10 | isVideoChannelNameValid | ||
11 | } from '../../helpers/custom-validators/video-channels' | ||
12 | import { isIdOrUUIDValid } from '../../helpers/index' | ||
7 | import { logger } from '../../helpers/logger' | 13 | import { logger } from '../../helpers/logger' |
8 | import { database as db } from '../../initializers' | 14 | import { database as db } from '../../initializers' |
9 | import { UserInstance } from '../../models' | 15 | import { UserInstance } from '../../models' |
10 | import { checkErrors } from './utils' | 16 | import { areValidationErrors, checkErrors } from './utils' |
11 | 17 | ||
12 | const listVideoAccountChannelsValidator = [ | 18 | const 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 | ||
99 | const 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 | ||
95 | export { | 123 | export { |
@@ -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 | // --------------------------------------------------------------------------- |