aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos.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/videos.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/videos.ts')
-rw-r--r--server/middlewares/validators/videos.ts26
1 files changed, 25 insertions, 1 deletions
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index df0eb7b96..5ffc85210 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -24,7 +24,8 @@ import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers'
24import { database as db } from '../../initializers/database' 24import { database as db } from '../../initializers/database'
25import { UserInstance } from '../../models/account/user-interface' 25import { UserInstance } from '../../models/account/user-interface'
26import { authenticate } from '../oauth' 26import { authenticate } from '../oauth'
27import { checkErrors } from './utils' 27import { areValidationErrors, checkErrors } from './utils'
28import { isVideoExistsPromise } from '../../helpers/index'
28 29
29const videosAddValidator = [ 30const videosAddValidator = [
30 body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage( 31 body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage(
@@ -230,6 +231,28 @@ const videoRateValidator = [
230 } 231 }
231] 232]
232 233
234const videosShareValidator = [
235 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
236 param('accountId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid account id'),
237
238 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
239 logger.debug('Checking videoShare parameters', { parameters: req.params })
240
241 if (areValidationErrors(req, res)) return
242 if (!await isVideoExistsPromise(req.params.id, res)) return
243
244 const share = await db.VideoShare.load(req.params.accountId, res.locals.video.id)
245 if (!share) {
246 return res.status(404)
247 .end()
248 }
249
250 res.locals.videoShare = share
251
252 return next()
253 }
254]
255
233// --------------------------------------------------------------------------- 256// ---------------------------------------------------------------------------
234 257
235export { 258export {
@@ -238,6 +261,7 @@ export {
238 videosGetValidator, 261 videosGetValidator,
239 videosRemoveValidator, 262 videosRemoveValidator,
240 videosSearchValidator, 263 videosSearchValidator,
264 videosShareValidator,
241 265
242 videoAbuseReportValidator, 266 videoAbuseReportValidator,
243 267