aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/video-captions.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-10-05 11:15:06 +0200
committerChocobozzz <me@florianbigard.com>2018-10-05 11:22:38 +0200
commit6e46de095d7169355dd83030f6ce4a582304153a (patch)
treedfa78e2008d3d135a00b798b05350b4975145acc /server/middlewares/validators/video-captions.ts
parenta585824160d016db7c9bff0e1cb1ffa3aaf73d74 (diff)
downloadPeerTube-6e46de095d7169355dd83030f6ce4a582304153a.tar.gz
PeerTube-6e46de095d7169355dd83030f6ce4a582304153a.tar.zst
PeerTube-6e46de095d7169355dd83030f6ce4a582304153a.zip
Add user history and resume videos
Diffstat (limited to 'server/middlewares/validators/video-captions.ts')
-rw-r--r--server/middlewares/validators/video-captions.ts71
1 files changed, 0 insertions, 71 deletions
diff --git a/server/middlewares/validators/video-captions.ts b/server/middlewares/validators/video-captions.ts
deleted file mode 100644
index 51ffd7f3c..000000000
--- a/server/middlewares/validators/video-captions.ts
+++ /dev/null
@@ -1,71 +0,0 @@
1import * as express from 'express'
2import { areValidationErrors } from './utils'
3import { checkUserCanManageVideo, isVideoExist } from '../../helpers/custom-validators/videos'
4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
5import { body, param } from 'express-validator/check'
6import { CONSTRAINTS_FIELDS } from '../../initializers'
7import { UserRight } from '../../../shared'
8import { logger } from '../../helpers/logger'
9import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
10import { cleanUpReqFiles } from '../../helpers/express-utils'
11
12const addVideoCaptionValidator = [
13 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
14 param('captionLanguage').custom(isVideoCaptionLanguageValid).not().isEmpty().withMessage('Should have a valid caption language'),
15 body('captionfile')
16 .custom((value, { req }) => isVideoCaptionFile(req.files, 'captionfile')).withMessage(
17 'This caption file is not supported or too large. Please, make sure it is of the following type : '
18 + CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME.join(', ')
19 ),
20
21 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
22 logger.debug('Checking addVideoCaption parameters', { parameters: req.body })
23
24 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
25 if (!await isVideoExist(req.params.videoId, res)) return cleanUpReqFiles(req)
26
27 // Check if the user who did the request is able to update the video
28 const user = res.locals.oauth.token.User
29 if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return cleanUpReqFiles(req)
30
31 return next()
32 }
33]
34
35const deleteVideoCaptionValidator = [
36 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
37 param('captionLanguage').custom(isVideoCaptionLanguageValid).not().isEmpty().withMessage('Should have a valid caption language'),
38
39 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
40 logger.debug('Checking deleteVideoCaption parameters', { parameters: req.params })
41
42 if (areValidationErrors(req, res)) return
43 if (!await isVideoExist(req.params.videoId, res)) return
44 if (!await isVideoCaptionExist(res.locals.video, req.params.captionLanguage, res)) return
45
46 // Check if the user who did the request is able to update the video
47 const user = res.locals.oauth.token.User
48 if (!checkUserCanManageVideo(user, res.locals.video, UserRight.UPDATE_ANY_VIDEO, res)) return
49
50 return next()
51 }
52]
53
54const listVideoCaptionsValidator = [
55 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
56
57 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
58 logger.debug('Checking listVideoCaptions parameters', { parameters: req.params })
59
60 if (areValidationErrors(req, res)) return
61 if (!await isVideoExist(req.params.videoId, res, 'id')) return
62
63 return next()
64 }
65]
66
67export {
68 addVideoCaptionValidator,
69 listVideoCaptionsValidator,
70 deleteVideoCaptionValidator
71}