diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/blacklist.ts | 35 | ||||
-rw-r--r-- | server/middlewares/validators/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/sort.ts | 5 |
3 files changed, 40 insertions, 1 deletions
diff --git a/server/middlewares/validators/blacklist.ts b/server/middlewares/validators/blacklist.ts new file mode 100644 index 000000000..fe8fa40a4 --- /dev/null +++ b/server/middlewares/validators/blacklist.ts | |||
@@ -0,0 +1,35 @@ | |||
1 | import { param } from 'express-validator/check' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { database as db } from '../../initializers/database' | ||
5 | import { checkErrors } from './utils' | ||
6 | import { logger } from '../../helpers' | ||
7 | |||
8 | const blacklistRemoveValidator = [ | ||
9 | param('id').isNumeric().not().isEmpty().withMessage('Should have a valid id'), | ||
10 | |||
11 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
12 | logger.debug('Checking blacklistRemove parameters.', { parameters: req.params }) | ||
13 | |||
14 | checkErrors(req, res, () => { | ||
15 | db.BlacklistedVideo.loadById(req.params.id) | ||
16 | .then(entry => { | ||
17 | if (!entry) return res.status(404).send('Blacklisted video not found') | ||
18 | |||
19 | res.locals.blacklistEntryToRemove = entry | ||
20 | |||
21 | next() | ||
22 | }) | ||
23 | .catch(err => { | ||
24 | logger.error('Error in blacklistRemove request validator', { error: err }) | ||
25 | return res.sendStatus(500) | ||
26 | }) | ||
27 | }) | ||
28 | } | ||
29 | ] | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
33 | export { | ||
34 | blacklistRemoveValidator | ||
35 | } | ||
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 42ba465ec..a6198e22c 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -4,3 +4,4 @@ export * from './pods' | |||
4 | export * from './sort' | 4 | export * from './sort' |
5 | export * from './users' | 5 | export * from './users' |
6 | export * from './videos' | 6 | export * from './videos' |
7 | export * from './blacklist' | ||
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts index 71b18acb0..a6f5ccb6b 100644 --- a/server/middlewares/validators/sort.ts +++ b/server/middlewares/validators/sort.ts | |||
@@ -9,17 +9,20 @@ import { SORTABLE_COLUMNS } from '../../initializers' | |||
9 | const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) | 9 | const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) |
10 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) | 10 | const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) |
11 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) | 11 | const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) |
12 | const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) | ||
12 | 13 | ||
13 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) | 14 | const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) |
14 | const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) | 15 | const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) |
15 | const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) | 16 | const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) |
17 | const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) | ||
16 | 18 | ||
17 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
18 | 20 | ||
19 | export { | 21 | export { |
20 | usersSortValidator, | 22 | usersSortValidator, |
21 | videoAbusesSortValidator, | 23 | videoAbusesSortValidator, |
22 | videosSortValidator | 24 | videosSortValidator, |
25 | blacklistSortValidator | ||
23 | } | 26 | } |
24 | 27 | ||
25 | // --------------------------------------------------------------------------- | 28 | // --------------------------------------------------------------------------- |