]>
Commit | Line | Data |
---|---|---|
1 | import { body, param } from 'express-validator/check' | |
2 | import * as express from 'express' | |
3 | import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | |
4 | import { doesVideoExist } from '../../../helpers/custom-validators/videos' | |
5 | import { areValidationErrors } from '../utils' | |
6 | import { logger } from '../../../helpers/logger' | |
7 | ||
8 | const videoWatchingValidator = [ | |
9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | |
10 | body('currentTime') | |
11 | .toInt() | |
12 | .isInt().withMessage('Should have correct current time'), | |
13 | ||
14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
15 | logger.debug('Checking videoWatching parameters', { parameters: req.body }) | |
16 | ||
17 | if (areValidationErrors(req, res)) return | |
18 | if (!await doesVideoExist(req.params.videoId, res, 'id')) return | |
19 | ||
20 | const user = res.locals.oauth.token.User | |
21 | if (user.videosHistoryEnabled === false) { | |
22 | logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id) | |
23 | return res.status(409).end() | |
24 | } | |
25 | ||
26 | return next() | |
27 | } | |
28 | ] | |
29 | ||
30 | // --------------------------------------------------------------------------- | |
31 | ||
32 | export { | |
33 | videoWatchingValidator | |
34 | } |