diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/sort.ts | 9 | ||||
-rw-r--r-- | server/middlewares/validators/account.ts | 19 | ||||
-rw-r--r-- | server/middlewares/validators/sort.ts | 3 |
3 files changed, 28 insertions, 3 deletions
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts index fdd6d419f..4f524b49a 100644 --- a/server/middlewares/sort.ts +++ b/server/middlewares/sort.ts | |||
@@ -2,6 +2,12 @@ import * as express from 'express' | |||
2 | import 'express-validator' | 2 | import 'express-validator' |
3 | import { SortType } from '../helpers/utils' | 3 | import { SortType } from '../helpers/utils' |
4 | 4 | ||
5 | function setAccountsSort (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
6 | if (!req.query.sort) req.query.sort = '-createdAt' | ||
7 | |||
8 | return next() | ||
9 | } | ||
10 | |||
5 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { | 11 | function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { |
6 | if (!req.query.sort) req.query.sort = '-createdAt' | 12 | if (!req.query.sort) req.query.sort = '-createdAt' |
7 | 13 | ||
@@ -82,5 +88,6 @@ export { | |||
82 | setFollowersSort, | 88 | setFollowersSort, |
83 | setFollowingSort, | 89 | setFollowingSort, |
84 | setJobsSort, | 90 | setJobsSort, |
85 | setVideoCommentThreadsSort | 91 | setVideoCommentThreadsSort, |
92 | setAccountsSort | ||
86 | } | 93 | } |
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 3573a9a50..ebc2fcf2d 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { param } from 'express-validator/check' | 2 | import { param } from 'express-validator/check' |
3 | import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' | 3 | import { isAccountIdExist, isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' |
4 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | ||
4 | import { logger } from '../../helpers/logger' | 5 | import { logger } from '../../helpers/logger' |
5 | import { areValidationErrors } from './utils' | 6 | import { areValidationErrors } from './utils' |
6 | 7 | ||
@@ -17,8 +18,22 @@ const localAccountValidator = [ | |||
17 | } | 18 | } |
18 | ] | 19 | ] |
19 | 20 | ||
21 | const accountsGetValidator = [ | ||
22 | param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'), | ||
23 | |||
24 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
25 | logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) | ||
26 | |||
27 | if (areValidationErrors(req, res)) return | ||
28 | if (!await isAccountIdExist(req.params.id, res)) return | ||
29 | |||
30 | return next() | ||
31 | } | ||
32 | ] | ||
33 | |||
20 | // --------------------------------------------------------------------------- | 34 | // --------------------------------------------------------------------------- |
21 | 35 | ||
22 | export { | 36 | export { |
23 | localAccountValidator | 37 | localAccountValidator, |
38 | accountsGetValidator | ||
24 | } | 39 | } |
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index e1d8d7d1b..72c6b34e3 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts | |||
@@ -6,6 +6,7 @@ import { areValidationErrors } from './utils' | |||
6 | 6 | ||
7 | // Initialize constants here for better performances | 7 | // Initialize constants here for better performances |
8 | const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) | 8 | const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) |
9 | const SORTABLE_ACCOUNTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.ACCOUNTS) | ||
9 | const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS) | 10 | const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS) |
10 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) | 11 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) |
11 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) | 12 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) |
@@ -16,6 +17,7 @@ const SORTABLE_FOLLOWERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOW | |||
16 | const SORTABLE_FOLLOWING_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWING) | 17 | const SORTABLE_FOLLOWING_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWING) |
17 | 18 | ||
18 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) | 19 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) |
20 | const accountsSortValidator = checkSort(SORTABLE_ACCOUNTS_COLUMNS) | ||
19 | const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS) | 21 | const jobsSortValidator = checkSort(SORTABLE_JOBS_COLUMNS) |
20 | const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) | 22 | const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) |
21 | const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) | 23 | const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) |
@@ -33,6 +35,7 @@ export { | |||
33 | videoChannelsSortValidator, | 35 | videoChannelsSortValidator, |
34 | videosSortValidator, | 36 | videosSortValidator, |
35 | blacklistSortValidator, | 37 | blacklistSortValidator, |
38 | accountsSortValidator, | ||
36 | followersSortValidator, | 39 | followersSortValidator, |
37 | followingSortValidator, | 40 | followingSortValidator, |
38 | jobsSortValidator, | 41 | jobsSortValidator, |