diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/follows.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/sort.ts | 5 | ||||
-rw-r--r-- | server/middlewares/validators/user-subscriptions.ts | 58 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 17 | ||||
-rw-r--r-- | server/middlewares/validators/webfinger.ts | 4 |
6 files changed, 83 insertions, 6 deletions
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index 040ee1f21..faefc1179 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts | |||
@@ -4,7 +4,7 @@ import { isTestInstance } from '../../helpers/core-utils' | |||
4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' | 4 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
5 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
6 | import { getServerActor } from '../../helpers/utils' | 6 | import { getServerActor } from '../../helpers/utils' |
7 | import { CONFIG } from '../../initializers' | 7 | import { CONFIG, SERVER_ACTOR_NAME } from '../../initializers' |
8 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | 8 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
9 | import { areValidationErrors } from './utils' | 9 | import { areValidationErrors } from './utils' |
10 | 10 | ||
@@ -38,7 +38,7 @@ const removeFollowingValidator = [ | |||
38 | if (areValidationErrors(req, res)) return | 38 | if (areValidationErrors(req, res)) return |
39 | 39 | ||
40 | const serverActor = await getServerActor() | 40 | const serverActor = await getServerActor() |
41 | const follow = await ActorFollowModel.loadByActorAndTargetHost(serverActor.id, req.params.host) | 41 | const follow = await ActorFollowModel.loadByActorAndTargetNameAndHost(serverActor.id, SERVER_ACTOR_NAME, req.params.host) |
42 | 42 | ||
43 | if (!follow) { | 43 | if (!follow) { |
44 | return res | 44 | return res |
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index ccbedd57d..940547a3e 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -6,6 +6,7 @@ export * from './follows' | |||
6 | export * from './feeds' | 6 | export * from './feeds' |
7 | export * from './sort' | 7 | export * from './sort' |
8 | export * from './users' | 8 | export * from './users' |
9 | export * from './user-subscriptions' | ||
9 | export * from './videos' | 10 | export * from './videos' |
10 | export * from './video-abuses' | 11 | export * from './video-abuses' |
11 | export * from './video-blacklist' | 12 | export * from './video-blacklist' |
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index d85611773..b30e97e61 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts | |||
@@ -14,6 +14,7 @@ const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACK | |||
14 | const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS) | 14 | const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS) |
15 | const SORTABLE_FOLLOWERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWERS) | 15 | const SORTABLE_FOLLOWERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWERS) |
16 | const SORTABLE_FOLLOWING_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWING) | 16 | const SORTABLE_FOLLOWING_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWING) |
17 | const SORTABLE_USER_SUBSCRIPTIONS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USER_SUBSCRIPTIONS) | ||
17 | 18 | ||
18 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) | 19 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) |
19 | const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) | 20 | const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) |
@@ -27,6 +28,7 @@ const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) | |||
27 | const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) | 28 | const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) |
28 | const followersSortValidator = checkSort(SORTABLE_FOLLOWERS_COLUMNS) | 29 | const followersSortValidator = checkSort(SORTABLE_FOLLOWERS_COLUMNS) |
29 | const followingSortValidator = checkSort(SORTABLE_FOLLOWING_COLUMNS) | 30 | const followingSortValidator = checkSort(SORTABLE_FOLLOWING_COLUMNS) |
31 | const userSubscriptionsSortValidator = checkSort(SORTABLE_USER_SUBSCRIPTIONS_COLUMNS) | ||
30 | 32 | ||
31 | // --------------------------------------------------------------------------- | 33 | // --------------------------------------------------------------------------- |
32 | 34 | ||
@@ -42,5 +44,6 @@ export { | |||
42 | followersSortValidator, | 44 | followersSortValidator, |
43 | followingSortValidator, | 45 | followingSortValidator, |
44 | jobsSortValidator, | 46 | jobsSortValidator, |
45 | videoCommentThreadsSortValidator | 47 | videoCommentThreadsSortValidator, |
48 | userSubscriptionsSortValidator | ||
46 | } | 49 | } |
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts new file mode 100644 index 000000000..f331b6c34 --- /dev/null +++ b/server/middlewares/validators/user-subscriptions.ts | |||
@@ -0,0 +1,58 @@ | |||
1 | import * as express from 'express' | ||
2 | import 'express-validator' | ||
3 | import { body, param } from 'express-validator/check' | ||
4 | import { logger } from '../../helpers/logger' | ||
5 | import { areValidationErrors } from './utils' | ||
6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | ||
7 | import { isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' | ||
8 | import { UserModel } from '../../models/account/user' | ||
9 | import { CONFIG } from '../../initializers' | ||
10 | |||
11 | const userSubscriptionAddValidator = [ | ||
12 | body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), | ||
13 | |||
14 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
15 | logger.debug('Checking userSubscriptionAddValidator parameters', { parameters: req.body }) | ||
16 | |||
17 | if (areValidationErrors(req, res)) return | ||
18 | |||
19 | return next() | ||
20 | } | ||
21 | ] | ||
22 | |||
23 | const userSubscriptionRemoveValidator = [ | ||
24 | param('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to unfollow'), | ||
25 | |||
26 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
27 | logger.debug('Checking unfollow parameters', { parameters: req.params }) | ||
28 | |||
29 | if (areValidationErrors(req, res)) return | ||
30 | |||
31 | let [ name, host ] = req.params.uri.split('@') | ||
32 | if (host === CONFIG.WEBSERVER.HOST) host = null | ||
33 | |||
34 | const user: UserModel = res.locals.oauth.token.User | ||
35 | const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHost(user.Account.Actor.id, name, host) | ||
36 | |||
37 | if (!subscription) { | ||
38 | return res | ||
39 | .status(404) | ||
40 | .json({ | ||
41 | error: `Subscription ${req.params.uri} not found.` | ||
42 | }) | ||
43 | .end() | ||
44 | } | ||
45 | |||
46 | res.locals.subscription = subscription | ||
47 | return next() | ||
48 | } | ||
49 | ] | ||
50 | |||
51 | // --------------------------------------------------------------------------- | ||
52 | |||
53 | export { | ||
54 | userSubscriptionAddValidator, | ||
55 | userSubscriptionRemoveValidator | ||
56 | } | ||
57 | |||
58 | // --------------------------------------------------------------------------- | ||
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 143ce9582..d354c7e05 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts | |||
@@ -4,6 +4,7 @@ import { UserRight } from '../../../shared' | |||
4 | import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' | 4 | import { isAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' |
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | 5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' |
6 | import { | 6 | import { |
7 | isLocalVideoChannelNameExist, | ||
7 | isVideoChannelDescriptionValid, | 8 | isVideoChannelDescriptionValid, |
8 | isVideoChannelExist, | 9 | isVideoChannelExist, |
9 | isVideoChannelNameValid, | 10 | isVideoChannelNameValid, |
@@ -100,6 +101,19 @@ const videoChannelsGetValidator = [ | |||
100 | } | 101 | } |
101 | ] | 102 | ] |
102 | 103 | ||
104 | const localVideoChannelValidator = [ | ||
105 | param('name').custom(isVideoChannelNameValid).withMessage('Should have a valid video channel name'), | ||
106 | |||
107 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
108 | logger.debug('Checking localVideoChannelValidator parameters', { parameters: req.params }) | ||
109 | |||
110 | if (areValidationErrors(req, res)) return | ||
111 | if (!await isLocalVideoChannelNameExist(req.params.name, res)) return | ||
112 | |||
113 | return next() | ||
114 | } | ||
115 | ] | ||
116 | |||
103 | // --------------------------------------------------------------------------- | 117 | // --------------------------------------------------------------------------- |
104 | 118 | ||
105 | export { | 119 | export { |
@@ -107,7 +121,8 @@ export { | |||
107 | videoChannelsAddValidator, | 121 | videoChannelsAddValidator, |
108 | videoChannelsUpdateValidator, | 122 | videoChannelsUpdateValidator, |
109 | videoChannelsRemoveValidator, | 123 | videoChannelsRemoveValidator, |
110 | videoChannelsGetValidator | 124 | videoChannelsGetValidator, |
125 | localVideoChannelValidator | ||
111 | } | 126 | } |
112 | 127 | ||
113 | // --------------------------------------------------------------------------- | 128 | // --------------------------------------------------------------------------- |
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts index 3b9645048..63a1678ec 100644 --- a/server/middlewares/validators/webfinger.ts +++ b/server/middlewares/validators/webfinger.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query } from 'express-validator/check' | 2 | import { query } from 'express-validator/check' |
3 | import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' | 3 | import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
5 | import { ActorModel } from '../../models/activitypub/actor' | 5 | import { ActorModel } from '../../models/activitypub/actor' |
6 | import { areValidationErrors } from './utils' | 6 | import { areValidationErrors } from './utils' |
7 | import { getHostWithPort } from '../../helpers/express-utils' | 7 | import { getHostWithPort } from '../../helpers/express-utils' |
8 | 8 | ||
9 | const webfingerValidator = [ | 9 | const webfingerValidator = [ |
10 | query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'), | 10 | query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'), |
11 | 11 | ||
12 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 12 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
13 | logger.debug('Checking webfinger parameters', { parameters: req.query }) | 13 | logger.debug('Checking webfinger parameters', { parameters: req.query }) |