diff options
Diffstat (limited to 'server/middlewares/validators/videos.ts')
-rw-r--r-- | server/middlewares/validators/videos.ts | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index 47825975c..e99cdefb1 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -1,9 +1,13 @@ | |||
1 | import 'express-validator' | ||
2 | import * as multer from 'multer' | ||
3 | import * as express from 'express' | ||
4 | |||
1 | import { database as db } from '../../initializers/database' | 5 | import { database as db } from '../../initializers/database' |
2 | import { checkErrors } from './utils' | 6 | import { checkErrors } from './utils' |
3 | import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers' | 7 | import { CONSTRAINTS_FIELDS, SEARCHABLE_COLUMNS } from '../../initializers' |
4 | import { logger, isVideoDurationValid } from '../../helpers' | 8 | import { logger, isVideoDurationValid } from '../../helpers' |
5 | 9 | ||
6 | function videosAddValidator (req, res, next) { | 10 | function videosAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
7 | req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files) | 11 | req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files) |
8 | req.checkBody('name', 'Should have a valid name').isVideoNameValid() | 12 | req.checkBody('name', 'Should have a valid name').isVideoNameValid() |
9 | req.checkBody('category', 'Should have a valid category').isVideoCategoryValid() | 13 | req.checkBody('category', 'Should have a valid category').isVideoCategoryValid() |
@@ -27,13 +31,13 @@ function videosAddValidator (req, res, next) { | |||
27 | return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).') | 31 | return res.status(400).send('Duration of the video file is too big (max: ' + CONSTRAINTS_FIELDS.VIDEOS.DURATION.max + 's).') |
28 | } | 32 | } |
29 | 33 | ||
30 | videoFile.duration = duration | 34 | videoFile['duration'] = duration |
31 | next() | 35 | next() |
32 | }) | 36 | }) |
33 | }) | 37 | }) |
34 | } | 38 | } |
35 | 39 | ||
36 | function videosUpdateValidator (req, res, next) { | 40 | function videosUpdateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
37 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 41 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) |
38 | req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() | 42 | req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() |
39 | req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid() | 43 | req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid() |
@@ -61,7 +65,7 @@ function videosUpdateValidator (req, res, next) { | |||
61 | }) | 65 | }) |
62 | } | 66 | } |
63 | 67 | ||
64 | function videosGetValidator (req, res, next) { | 68 | function videosGetValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
65 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 69 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) |
66 | 70 | ||
67 | logger.debug('Checking videosGet parameters', { parameters: req.params }) | 71 | logger.debug('Checking videosGet parameters', { parameters: req.params }) |
@@ -71,7 +75,7 @@ function videosGetValidator (req, res, next) { | |||
71 | }) | 75 | }) |
72 | } | 76 | } |
73 | 77 | ||
74 | function videosRemoveValidator (req, res, next) { | 78 | function videosRemoveValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
75 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 79 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) |
76 | 80 | ||
77 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) | 81 | logger.debug('Checking videosRemove parameters', { parameters: req.params }) |
@@ -88,7 +92,7 @@ function videosRemoveValidator (req, res, next) { | |||
88 | }) | 92 | }) |
89 | } | 93 | } |
90 | 94 | ||
91 | function videosSearchValidator (req, res, next) { | 95 | function videosSearchValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
92 | const searchableColumns = SEARCHABLE_COLUMNS.VIDEOS | 96 | const searchableColumns = SEARCHABLE_COLUMNS.VIDEOS |
93 | req.checkParams('value', 'Should have a valid search').notEmpty() | 97 | req.checkParams('value', 'Should have a valid search').notEmpty() |
94 | req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns) | 98 | req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns) |
@@ -98,7 +102,7 @@ function videosSearchValidator (req, res, next) { | |||
98 | checkErrors(req, res, next) | 102 | checkErrors(req, res, next) |
99 | } | 103 | } |
100 | 104 | ||
101 | function videoAbuseReportValidator (req, res, next) { | 105 | function videoAbuseReportValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
102 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 106 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) |
103 | req.checkBody('reason', 'Should have a valid reason').isVideoAbuseReasonValid() | 107 | req.checkBody('reason', 'Should have a valid reason').isVideoAbuseReasonValid() |
104 | 108 | ||
@@ -109,7 +113,7 @@ function videoAbuseReportValidator (req, res, next) { | |||
109 | }) | 113 | }) |
110 | } | 114 | } |
111 | 115 | ||
112 | function videoRateValidator (req, res, next) { | 116 | function videoRateValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
113 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 117 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) |
114 | req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid() | 118 | req.checkBody('rating', 'Should have a valid rate type').isVideoRatingTypeValid() |
115 | 119 | ||
@@ -120,7 +124,7 @@ function videoRateValidator (req, res, next) { | |||
120 | }) | 124 | }) |
121 | } | 125 | } |
122 | 126 | ||
123 | function videosBlacklistValidator (req, res, next) { | 127 | function videosBlacklistValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
124 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) | 128 | req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) |
125 | 129 | ||
126 | logger.debug('Checking videosBlacklist parameters', { parameters: req.params }) | 130 | logger.debug('Checking videosBlacklist parameters', { parameters: req.params }) |
@@ -150,7 +154,7 @@ export { | |||
150 | 154 | ||
151 | // --------------------------------------------------------------------------- | 155 | // --------------------------------------------------------------------------- |
152 | 156 | ||
153 | function checkVideoExists (id, res, callback) { | 157 | function checkVideoExists (id: string, res: express.Response, callback: () => void) { |
154 | db.Video.loadAndPopulateAuthorAndPodAndTags(id, function (err, video) { | 158 | db.Video.loadAndPopulateAuthorAndPodAndTags(id, function (err, video) { |
155 | if (err) { | 159 | if (err) { |
156 | logger.error('Error in video request validator.', { error: err }) | 160 | logger.error('Error in video request validator.', { error: err }) |
@@ -164,7 +168,7 @@ function checkVideoExists (id, res, callback) { | |||
164 | }) | 168 | }) |
165 | } | 169 | } |
166 | 170 | ||
167 | function checkUserCanDeleteVideo (userId, res, callback) { | 171 | function checkUserCanDeleteVideo (userId: number, res: express.Response, callback: () => void) { |
168 | // Retrieve the user who did the request | 172 | // Retrieve the user who did the request |
169 | db.User.loadById(userId, function (err, user) { | 173 | db.User.loadById(userId, function (err, user) { |
170 | if (err) { | 174 | if (err) { |
@@ -190,7 +194,7 @@ function checkUserCanDeleteVideo (userId, res, callback) { | |||
190 | }) | 194 | }) |
191 | } | 195 | } |
192 | 196 | ||
193 | function checkVideoIsBlacklistable (req, res, callback) { | 197 | function checkVideoIsBlacklistable (req: express.Request, res: express.Response, callback: () => void) { |
194 | if (res.locals.video.isOwned() === true) { | 198 | if (res.locals.video.isOwned() === true) { |
195 | return res.status(403).send('Cannot blacklist a local video') | 199 | return res.status(403).send('Cannot blacklist a local video') |
196 | } | 200 | } |