]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/validators/videos/video-watch.ts
fix plugin storage return value when storing a Json array
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / videos / video-watch.ts
CommitLineData
41fb13c3 1import express from 'express'
d4a8e7a6 2import { body } from 'express-validator'
c0e8b12e 3import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
d4a8e7a6 4import { toIntOrNull } from '../../../helpers/custom-validators/misc'
6e46de09 5import { logger } from '../../../helpers/logger'
d4a8e7a6 6import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
6e46de09
C
7
8const videoWatchingValidator = [
d4a8e7a6
C
9 isValidVideoIdParam('videoId'),
10
6e46de09 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)
76148b27
RK
24 return res.fail({
25 status: HttpStatusCode.CONFLICT_409,
26 message: 'Video history is disabled'
27 })
8b9a525a
C
28 }
29
6e46de09
C
30 return next()
31 }
32]
33
34// ---------------------------------------------------------------------------
35
36export {
37 videoWatchingValidator
38}