import * as express from 'express'
import 'express-validator'
-import { body, param, ValidationChain } from 'express-validator/check'
+import { body, param, query, ValidationChain } from 'express-validator/check'
import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
import {
isBooleanValid,
isIdOrUUIDValid,
isIdValid,
isUUIDValid,
+ toArray,
toIntOrNull,
toValueOrNull
} from '../../../helpers/custom-validators/misc'
isVideoDescriptionValid,
isVideoExist,
isVideoFile,
+ isVideoFilterValid,
isVideoImage,
isVideoLanguageValid,
isVideoLicenceValid,
isVideoNameValid,
isVideoPrivacyValid,
- isVideoRatingTypeValid,
isVideoSupportValid,
isVideoTagsValid
} from '../../../helpers/custom-validators/videos'
import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils'
import { logger } from '../../../helpers/logger'
import { CONSTRAINTS_FIELDS } from '../../../initializers'
-import { VideoShareModel } from '../../../models/video/video-share'
import { authenticate } from '../../oauth'
import { areValidationErrors } from '../utils'
import { cleanUpReqFiles } from '../../../helpers/express-utils'
import { VideoChangeOwnershipModel } from '../../../models/video/video-change-ownership'
import { AccountModel } from '../../../models/account/account'
import { VideoFetchType } from '../../../helpers/video'
+import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
const videosAddValidator = getCommonVideoAttributes().concat([
body('videofile')
}
]
-const videoRateValidator = [
- param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
- body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'),
-
- async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- logger.debug('Checking videoRate parameters', { parameters: req.body })
-
- if (areValidationErrors(req, res)) return
- if (!await isVideoExist(req.params.id, res)) return
-
- return next()
- }
-]
-
-const videosShareValidator = [
- param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
- param('accountId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid account id'),
-
- async (req: express.Request, res: express.Response, next: express.NextFunction) => {
- logger.debug('Checking videoShare parameters', { parameters: req.params })
-
- if (areValidationErrors(req, res)) return
- if (!await isVideoExist(req.params.id, res)) return
-
- const share = await VideoShareModel.load(req.params.accountId, res.locals.video.id, undefined)
- if (!share) {
- return res.status(404)
- .end()
- }
-
- res.locals.videoShare = share
- return next()
- }
-]
-
const videosChangeOwnershipValidator = [
param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
] as (ValidationChain | express.Handler)[]
}
+const commonVideosFiltersValidator = [
+ query('categoryOneOf')
+ .optional()
+ .customSanitizer(toArray)
+ .custom(isNumberArray).withMessage('Should have a valid one of category array'),
+ query('licenceOneOf')
+ .optional()
+ .customSanitizer(toArray)
+ .custom(isNumberArray).withMessage('Should have a valid one of licence array'),
+ query('languageOneOf')
+ .optional()
+ .customSanitizer(toArray)
+ .custom(isStringArray).withMessage('Should have a valid one of language array'),
+ query('tagsOneOf')
+ .optional()
+ .customSanitizer(toArray)
+ .custom(isStringArray).withMessage('Should have a valid one of tags array'),
+ query('tagsAllOf')
+ .optional()
+ .customSanitizer(toArray)
+ .custom(isStringArray).withMessage('Should have a valid all of tags array'),
+ query('nsfw')
+ .optional()
+ .custom(isNSFWQueryValid).withMessage('Should have a valid NSFW attribute'),
+ query('filter')
+ .optional()
+ .custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking commons video filters query', { parameters: req.query })
+
+ if (areValidationErrors(req, res)) return
+
+ const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined
+ if (req.query.filter === 'all-local' && (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)) {
+ res.status(401)
+ .json({ error: 'You are not allowed to see all local videos.' })
+
+ return
+ }
+
+ return next()
+ }
+]
+
// ---------------------------------------------------------------------------
export {
videosGetValidator,
videosCustomGetValidator,
videosRemoveValidator,
- videosShareValidator,
-
- videoRateValidator,
videosChangeOwnershipValidator,
videosTerminateChangeOwnershipValidator,
videosAcceptChangeOwnershipValidator,
- getCommonVideoAttributes
+ getCommonVideoAttributes,
+
+ commonVideosFiltersValidator
}
// ---------------------------------------------------------------------------