diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-14 18:06:56 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-14 18:06:56 +0200 |
commit | 2baea0c77cc765f7cbca9c9a2f4272268892a35c (patch) | |
tree | 47b1be5535439409a97eb80c0222c9c821b83dae /server/middlewares | |
parent | bf079b7bfd7f0fb75ceb28e333bb4b74d8840dd4 (diff) | |
download | PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.tar.gz PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.tar.zst PeerTube-2baea0c77cc765f7cbca9c9a2f4272268892a35c.zip |
Add ability for uploaders to schedule video update
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/videos.ts | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index e181aebdb..9fe5a253b 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts | |||
@@ -2,8 +2,17 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param, query } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { UserRight, VideoPrivacy } from '../../../shared' | 4 | import { UserRight, VideoPrivacy } from '../../../shared' |
5 | import { isBooleanValid, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntOrNull, toValueOrNull } from '../../helpers/custom-validators/misc' | ||
6 | import { | 5 | import { |
6 | isBooleanValid, | ||
7 | isDateValid, | ||
8 | isIdOrUUIDValid, | ||
9 | isIdValid, | ||
10 | isUUIDValid, | ||
11 | toIntOrNull, | ||
12 | toValueOrNull | ||
13 | } from '../../helpers/custom-validators/misc' | ||
14 | import { | ||
15 | isScheduleVideoUpdatePrivacyValid, | ||
7 | isVideoAbuseReasonValid, | 16 | isVideoAbuseReasonValid, |
8 | isVideoCategoryValid, | 17 | isVideoCategoryValid, |
9 | isVideoChannelOfAccountExist, | 18 | isVideoChannelOfAccountExist, |
@@ -84,14 +93,21 @@ const videosAddValidator = [ | |||
84 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), | 93 | .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), |
85 | body('channelId') | 94 | body('channelId') |
86 | .toInt() | 95 | .toInt() |
87 | .custom(isIdValid) | 96 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
88 | .withMessage('Should have correct video channel id'), | 97 | body('scheduleUpdate.updateAt') |
98 | .optional() | ||
99 | .custom(isDateValid).withMessage('Should have a valid schedule update date'), | ||
100 | body('scheduleUpdate.privacy') | ||
101 | .optional() | ||
102 | .toInt() | ||
103 | .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy'), | ||
89 | 104 | ||
90 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 105 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
91 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) | 106 | logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) |
92 | 107 | ||
93 | if (areValidationErrors(req, res)) return | 108 | if (areValidationErrors(req, res)) return |
94 | if (areErrorsInVideoImageFiles(req, res)) return | 109 | if (areErrorsInVideoImageFiles(req, res)) return |
110 | if (areErrorsInScheduleUpdate(req, res)) return | ||
95 | 111 | ||
96 | const videoFile: Express.Multer.File = req.files['videofile'][0] | 112 | const videoFile: Express.Multer.File = req.files['videofile'][0] |
97 | const user = res.locals.oauth.token.User | 113 | const user = res.locals.oauth.token.User |
@@ -183,12 +199,20 @@ const videosUpdateValidator = [ | |||
183 | .optional() | 199 | .optional() |
184 | .toInt() | 200 | .toInt() |
185 | .custom(isIdValid).withMessage('Should have correct video channel id'), | 201 | .custom(isIdValid).withMessage('Should have correct video channel id'), |
202 | body('scheduleUpdate.updateAt') | ||
203 | .optional() | ||
204 | .custom(isDateValid).withMessage('Should have a valid schedule update date'), | ||
205 | body('scheduleUpdate.privacy') | ||
206 | .optional() | ||
207 | .toInt() | ||
208 | .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy'), | ||
186 | 209 | ||
187 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 210 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
188 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) | 211 | logger.debug('Checking videosUpdate parameters', { parameters: req.body }) |
189 | 212 | ||
190 | if (areValidationErrors(req, res)) return | 213 | if (areValidationErrors(req, res)) return |
191 | if (areErrorsInVideoImageFiles(req, res)) return | 214 | if (areErrorsInVideoImageFiles(req, res)) return |
215 | if (areErrorsInScheduleUpdate(req, res)) return | ||
192 | if (!await isVideoExist(req.params.id, res)) return | 216 | if (!await isVideoExist(req.params.id, res)) return |
193 | 217 | ||
194 | const video = res.locals.video | 218 | const video = res.locals.video |
@@ -371,7 +395,7 @@ function areErrorsInVideoImageFiles (req: express.Request, res: express.Response | |||
371 | const imageFile = req.files[ imageField ][ 0 ] as Express.Multer.File | 395 | const imageFile = req.files[ imageField ][ 0 ] as Express.Multer.File |
372 | if (imageFile.size > CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max) { | 396 | if (imageFile.size > CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max) { |
373 | res.status(400) | 397 | res.status(400) |
374 | .send({ error: `The size of the ${imageField} is too big (>${CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max}).` }) | 398 | .json({ error: `The size of the ${imageField} is too big (>${CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max}).` }) |
375 | .end() | 399 | .end() |
376 | return true | 400 | return true |
377 | } | 401 | } |
@@ -379,3 +403,17 @@ function areErrorsInVideoImageFiles (req: express.Request, res: express.Response | |||
379 | 403 | ||
380 | return false | 404 | return false |
381 | } | 405 | } |
406 | |||
407 | function areErrorsInScheduleUpdate (req: express.Request, res: express.Response) { | ||
408 | if (req.body.scheduleUpdate) { | ||
409 | if (!req.body.scheduleUpdate.updateAt) { | ||
410 | res.status(400) | ||
411 | .json({ error: 'Schedule update at is mandatory.' }) | ||
412 | .end() | ||
413 | |||
414 | return true | ||
415 | } | ||
416 | } | ||
417 | |||
418 | return false | ||
419 | } | ||