diff options
Diffstat (limited to 'server/middlewares/validators/user-subscriptions.ts')
-rw-r--r-- | server/middlewares/validators/user-subscriptions.ts | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts index d8c26c742..c5f8d9d4c 100644 --- a/server/middlewares/validators/user-subscriptions.ts +++ b/server/middlewares/validators/user-subscriptions.ts | |||
@@ -1,12 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { body, param } from 'express-validator/check' | 3 | import { body, param, query } from 'express-validator/check' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 5 | import { areValidationErrors } from './utils' |
6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
7 | import { isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' | 7 | import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' |
8 | import { UserModel } from '../../models/account/user' | 8 | import { UserModel } from '../../models/account/user' |
9 | import { CONFIG } from '../../initializers' | 9 | import { CONFIG } from '../../initializers' |
10 | import { toArray } from '../../helpers/custom-validators/misc' | ||
10 | 11 | ||
11 | const userSubscriptionAddValidator = [ | 12 | const userSubscriptionAddValidator = [ |
12 | body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), | 13 | body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), |
@@ -20,6 +21,20 @@ const userSubscriptionAddValidator = [ | |||
20 | } | 21 | } |
21 | ] | 22 | ] |
22 | 23 | ||
24 | const areSubscriptionsExistValidator = [ | ||
25 | query('uris') | ||
26 | .customSanitizer(toArray) | ||
27 | .custom(areValidActorHandles).withMessage('Should have a valid uri array'), | ||
28 | |||
29 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
30 | logger.debug('Checking areSubscriptionsExistValidator parameters', { parameters: req.query }) | ||
31 | |||
32 | if (areValidationErrors(req, res)) return | ||
33 | |||
34 | return next() | ||
35 | } | ||
36 | ] | ||
37 | |||
23 | const userSubscriptionGetValidator = [ | 38 | const userSubscriptionGetValidator = [ |
24 | param('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to unfollow'), | 39 | param('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to unfollow'), |
25 | 40 | ||
@@ -32,7 +47,7 @@ const userSubscriptionGetValidator = [ | |||
32 | if (host === CONFIG.WEBSERVER.HOST) host = null | 47 | if (host === CONFIG.WEBSERVER.HOST) host = null |
33 | 48 | ||
34 | const user: UserModel = res.locals.oauth.token.User | 49 | const user: UserModel = res.locals.oauth.token.User |
35 | const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHost(user.Account.Actor.id, name, host) | 50 | const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host) |
36 | 51 | ||
37 | if (!subscription || !subscription.ActorFollowing.VideoChannel) { | 52 | if (!subscription || !subscription.ActorFollowing.VideoChannel) { |
38 | return res | 53 | return res |
@@ -51,8 +66,7 @@ const userSubscriptionGetValidator = [ | |||
51 | // --------------------------------------------------------------------------- | 66 | // --------------------------------------------------------------------------- |
52 | 67 | ||
53 | export { | 68 | export { |
69 | areSubscriptionsExistValidator, | ||
54 | userSubscriptionAddValidator, | 70 | userSubscriptionAddValidator, |
55 | userSubscriptionGetValidator | 71 | userSubscriptionGetValidator |
56 | } | 72 | } |
57 | |||
58 | // --------------------------------------------------------------------------- | ||