aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/user-subscriptions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/user-subscriptions.ts')
-rw-r--r--server/middlewares/validators/user-subscriptions.ts24
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param } from 'express-validator/check' 3import { body, param, query } from 'express-validator/check'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6import { ActorFollowModel } from '../../models/activitypub/actor-follow' 6import { ActorFollowModel } from '../../models/activitypub/actor-follow'
7import { isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' 7import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
8import { UserModel } from '../../models/account/user' 8import { UserModel } from '../../models/account/user'
9import { CONFIG } from '../../initializers' 9import { CONFIG } from '../../initializers'
10import { toArray } from '../../helpers/custom-validators/misc'
10 11
11const userSubscriptionAddValidator = [ 12const 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
24const 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
23const userSubscriptionGetValidator = [ 38const 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
53export { 68export {
69 areSubscriptionsExistValidator,
54 userSubscriptionAddValidator, 70 userSubscriptionAddValidator,
55 userSubscriptionGetValidator 71 userSubscriptionGetValidator
56} 72}
57
58// ---------------------------------------------------------------------------