aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/videos.ts
diff options
context:
space:
mode:
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