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