]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/videos/video-watch.ts
Fetch directly all video attributes for get API
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-watch.ts
CommitLineData
6e46de09 1import * as express from 'express'
10363c74
C
2import { body, param } from 'express-validator'
3import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
c8861d5d 4import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
6e46de09 5import { logger } from '../../../helpers/logger'
10363c74 6import { areValidationErrors, doesVideoExist } from '../shared'
6e46de09
C
7
8const videoWatchingValidator = [
9 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
10 body('currentTime')
c8861d5d 11 .customSanitizer(toIntOrNull)
6e46de09
C
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
0f6acda1 18 if (!await doesVideoExist(req.params.videoId, res, 'id')) return
6e46de09 19
dae86118 20 const user = res.locals.oauth.token.User
8b9a525a
C
21 if (user.videosHistoryEnabled === false) {
22 logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id)
76148b27
RK
23 return res.fail({
24 status: HttpStatusCode.CONFLICT_409,
25 message: 'Video history is disabled'
26 })
8b9a525a
C
27 }
28
6e46de09
C
29 return next()
30 }
31]
32
33// ---------------------------------------------------------------------------
34
35export {
36 videoWatchingValidator
37}