]>
Commit | Line | Data |
---|---|---|
1 | import express from 'express' | |
2 | import { body } from 'express-validator' | |
3 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | |
4 | import { toIntOrNull } from '../../../helpers/custom-validators/misc' | |
5 | import { logger } from '../../../helpers/logger' | |
6 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared' | |
7 | ||
8 | const videoWatchingValidator = [ | |
9 | isValidVideoIdParam('videoId'), | |
10 | ||
11 | body('currentTime') | |
12 | .customSanitizer(toIntOrNull) | |
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 | |
19 | if (!await doesVideoExist(req.params.videoId, res, 'id')) return | |
20 | ||
21 | const user = res.locals.oauth.token.User | |
22 | if (user.videosHistoryEnabled === false) { | |
23 | logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id) | |
24 | return res.fail({ | |
25 | status: HttpStatusCode.CONFLICT_409, | |
26 | message: 'Video history is disabled' | |
27 | }) | |
28 | } | |
29 | ||
30 | return next() | |
31 | } | |
32 | ] | |
33 | ||
34 | // --------------------------------------------------------------------------- | |
35 | ||
36 | export { | |
37 | videoWatchingValidator | |
38 | } |