diff options
Diffstat (limited to 'server/middlewares')
-rw-r--r-- | server/middlewares/validators/feeds.ts | 35 | ||||
-rw-r--r-- | server/middlewares/validators/index.ts | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts new file mode 100644 index 000000000..6a8cfce86 --- /dev/null +++ b/server/middlewares/validators/feeds.ts | |||
@@ -0,0 +1,35 @@ | |||
1 | import * as express from 'express' | ||
2 | import { param, query } from 'express-validator/check' | ||
3 | import { isAccountIdExist, isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' | ||
4 | import { join } from 'path' | ||
5 | import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' | ||
6 | import { logger } from '../../helpers/logger' | ||
7 | import { areValidationErrors } from './utils' | ||
8 | import { isValidRSSFeed } from '../../helpers/custom-validators/feeds' | ||
9 | |||
10 | const feedsValidator = [ | ||
11 | param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | ||
12 | query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), | ||
13 | query('accountId').optional().custom(isIdOrUUIDValid), | ||
14 | query('accountName').optional().custom(isAccountNameValid), | ||
15 | |||
16 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
17 | logger.debug('Checking feeds parameters', { parameters: req.query }) | ||
18 | |||
19 | if (areValidationErrors(req, res)) return | ||
20 | |||
21 | if (req.query.accountId) { | ||
22 | if (!await isAccountIdExist(req.query.accountId, res)) return | ||
23 | } else if (req.query.accountName) { | ||
24 | if (!await isLocalAccountNameExist(req.query.accountName, res)) return | ||
25 | } | ||
26 | |||
27 | return next() | ||
28 | } | ||
29 | ] | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
33 | export { | ||
34 | feedsValidator | ||
35 | } | ||
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 9840e8f65..b69e1f14b 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -3,6 +3,7 @@ export * from './oembed' | |||
3 | export * from './activitypub' | 3 | export * from './activitypub' |
4 | export * from './pagination' | 4 | export * from './pagination' |
5 | export * from './follows' | 5 | export * from './follows' |
6 | export * from './feeds' | ||
6 | export * from './sort' | 7 | export * from './sort' |
7 | export * from './users' | 8 | export * from './users' |
8 | export * from './videos' | 9 | export * from './videos' |