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'
8 const videoWatchingValidator = [
9 isValidVideoIdParam('videoId'),
12 .customSanitizer(toIntOrNull)
13 .isInt().withMessage('Should have correct current time'),
15 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
16 logger.debug('Checking videoWatching parameters', { parameters: req.body })
18 if (areValidationErrors(req, res)) return
19 if (!await doesVideoExist(req.params.videoId, res, 'id')) return
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)
25 status: HttpStatusCode.CONFLICT_409,
26 message: 'Video history is disabled'
34 // ---------------------------------------------------------------------------
37 videoWatchingValidator