+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('privacyOneOf')
+ .optional()
+ .customSanitizer(toArray)
+ .custom(isNumberArray).withMessage('Should have a valid one of privacy 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(isBooleanBothQueryValid).withMessage('Should have a valid NSFW attribute'),
+ query('isLive')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid live boolean'),
+ query('filter')
+ .optional()
+ .custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'),
+ query('include')
+ .optional()
+ .custom(isVideoIncludeValid).withMessage('Should have a valid include attribute'),
+ query('isLocal')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid local boolean'),
+ query('hasHLSFiles')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid has hls boolean'),
+ query('hasWebtorrentFiles')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid has webtorrent boolean'),
+ query('skipCount')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid skip count boolean'),
+ query('search')
+ .optional()
+ .custom(exists).withMessage('Should have a valid search'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ logger.debug('Checking commons video filters query', { parameters: req.query })
+
+ if (areValidationErrors(req, res)) return
+
+ // FIXME: deprecated in 4.0, to remove
+ {
+ if (req.query.filter === 'all-local') {
+ req.query.include = VideoInclude.NOT_PUBLISHED_STATE
+ req.query.isLocal = true
+ req.query.privacyOneOf = getAllPrivacies()
+ } else if (req.query.filter === 'all') {
+ req.query.include = VideoInclude.NOT_PUBLISHED_STATE
+ req.query.privacyOneOf = getAllPrivacies()
+ } else if (req.query.filter === 'local') {
+ req.query.isLocal = true
+ }
+
+ req.query.filter = undefined
+ }
+
+ const user = res.locals.oauth?.token.User
+
+ if ((!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) !== true)) {
+ if (req.query.include || req.query.privacyOneOf) {
+ return res.fail({
+ status: HttpStatusCode.UNAUTHORIZED_401,
+ message: 'You are not allowed to see all videos.'
+ })
+ }
+ }
+
+ return next()
+ }
+]
+