+const commonVideosFiltersValidator = [
+ query('categoryOneOf')
+ .optional()
+ .customSanitizer(arrayify)
+ .custom(isNumberArray).withMessage('Should have a valid categoryOneOf array'),
+ query('licenceOneOf')
+ .optional()
+ .customSanitizer(arrayify)
+ .custom(isNumberArray).withMessage('Should have a valid licenceOneOf array'),
+ query('languageOneOf')
+ .optional()
+ .customSanitizer(arrayify)
+ .custom(isStringArray).withMessage('Should have a valid languageOneOf array'),
+ query('privacyOneOf')
+ .optional()
+ .customSanitizer(arrayify)
+ .custom(isNumberArray).withMessage('Should have a valid privacyOneOf array'),
+ query('tagsOneOf')
+ .optional()
+ .customSanitizer(arrayify)
+ .custom(isStringArray).withMessage('Should have a valid tagsOneOf array'),
+ query('tagsAllOf')
+ .optional()
+ .customSanitizer(arrayify)
+ .custom(isStringArray).withMessage('Should have a valid tagsAllOf array'),
+ query('nsfw')
+ .optional()
+ .custom(isBooleanBothQueryValid),
+ query('isLive')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'),
+ query('filter')
+ .optional()
+ .custom(isVideoFilterValid),
+ query('include')
+ .optional()
+ .custom(isVideoIncludeValid),
+ query('isLocal')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid isLocal boolean'),
+ query('hasHLSFiles')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid hasHLSFiles boolean'),
+ query('hasWebtorrentFiles')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid hasWebtorrentFiles boolean'),
+ query('skipCount')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .custom(isBooleanValid).withMessage('Should have a valid skipCount boolean'),
+ query('search')
+ .optional()
+ .custom(exists),
+ query('excludeAlreadyWatched')
+ .optional()
+ .customSanitizer(toBooleanOrNull)
+ .isBoolean().withMessage('Should be a valid excludeAlreadyWatched boolean'),
+
+ (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ 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.'
+ })
+ }
+ }
+
+ if (!user && exists(req.query.excludeAlreadyWatched)) {
+ res.fail({
+ status: HttpStatusCode.BAD_REQUEST_400,
+ message: 'Cannot use excludeAlreadyWatched parameter when auth token is not provided'
+ })
+ return false
+ }
+ return next()
+ }
+]
+