diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-20 09:05:43 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-10-20 09:25:44 +0200 |
commit | 978c87e7f58b6673fe60f04f1767bc9e02ea4936 (patch) | |
tree | e7d48735d4099fec8c7732f33e7dadb09c0eac80 /server/middlewares/validators | |
parent | 7e76cc380040e40a2292a9dc825f037c9b538030 (diff) | |
download | PeerTube-978c87e7f58b6673fe60f04f1767bc9e02ea4936.tar.gz PeerTube-978c87e7f58b6673fe60f04f1767bc9e02ea4936.tar.zst PeerTube-978c87e7f58b6673fe60f04f1767bc9e02ea4936.zip |
Add channel filters for my videos/followers
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/users.ts | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index c6eeeaf18..8f1a7801f 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -4,7 +4,7 @@ import { omit } from 'lodash' | |||
4 | import { Hooks } from '@server/lib/plugins/hooks' | 4 | import { Hooks } from '@server/lib/plugins/hooks' |
5 | import { MUserDefault } from '@server/types/models' | 5 | import { MUserDefault } from '@server/types/models' |
6 | import { HttpStatusCode, UserRegister, UserRole } from '@shared/models' | 6 | import { HttpStatusCode, UserRegister, UserRole } from '@shared/models' |
7 | import { toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 7 | import { isBooleanValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' |
8 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' | 8 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
9 | import { | 9 | import { |
10 | isUserAdminFlagsValid, | 10 | isUserAdminFlagsValid, |
@@ -31,7 +31,7 @@ import { Redis } from '../../lib/redis' | |||
31 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup' | 31 | import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../lib/signup' |
32 | import { ActorModel } from '../../models/actor/actor' | 32 | import { ActorModel } from '../../models/actor/actor' |
33 | import { UserModel } from '../../models/user/user' | 33 | import { UserModel } from '../../models/user/user' |
34 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from './shared' | 34 | import { areValidationErrors, doesVideoChannelIdExist, doesVideoExist, isValidVideoIdParam } from './shared' |
35 | 35 | ||
36 | const usersListValidator = [ | 36 | const usersListValidator = [ |
37 | query('blocked') | 37 | query('blocked') |
@@ -318,6 +318,28 @@ const usersVideoRatingValidator = [ | |||
318 | } | 318 | } |
319 | ] | 319 | ] |
320 | 320 | ||
321 | const usersVideosValidator = [ | ||
322 | query('isLive') | ||
323 | .optional() | ||
324 | .customSanitizer(toBooleanOrNull) | ||
325 | .custom(isBooleanValid).withMessage('Should have a valid live boolean'), | ||
326 | |||
327 | query('channelId') | ||
328 | .optional() | ||
329 | .customSanitizer(toIntOrNull) | ||
330 | .custom(isIdValid).withMessage('Should have a valid channel id'), | ||
331 | |||
332 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
333 | logger.debug('Checking usersVideosValidator parameters', { parameters: req.params }) | ||
334 | |||
335 | if (areValidationErrors(req, res)) return | ||
336 | |||
337 | if (req.query.channelId && !await doesVideoChannelIdExist(req.query.channelId, res)) return | ||
338 | |||
339 | return next() | ||
340 | } | ||
341 | ] | ||
342 | |||
321 | const ensureUserRegistrationAllowed = [ | 343 | const ensureUserRegistrationAllowed = [ |
322 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 344 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
323 | const allowedParams = { | 345 | const allowedParams = { |
@@ -513,6 +535,7 @@ export { | |||
513 | ensureUserRegistrationAllowed, | 535 | ensureUserRegistrationAllowed, |
514 | ensureUserRegistrationAllowedForIP, | 536 | ensureUserRegistrationAllowedForIP, |
515 | usersGetValidator, | 537 | usersGetValidator, |
538 | usersVideosValidator, | ||
516 | usersAskResetPasswordValidator, | 539 | usersAskResetPasswordValidator, |
517 | usersResetPasswordValidator, | 540 | usersResetPasswordValidator, |
518 | usersAskSendVerifyEmailValidator, | 541 | usersAskSendVerifyEmailValidator, |