aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r--server/middlewares/validators/feeds.ts36
1 files changed, 32 insertions, 4 deletions
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts
index 1bef9891b..29f6c87be 100644
--- a/server/middlewares/validators/feeds.ts
+++ b/server/middlewares/validators/feeds.ts
@@ -12,9 +12,37 @@ import {
12 doesVideoChannelNameWithHostExist 12 doesVideoChannelNameWithHostExist
13} from '../../helpers/middlewares' 13} from '../../helpers/middlewares'
14 14
15const videoFeedsValidator = [ 15const feedsFormatValidator = [
16 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), 16 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
17 query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), 17 query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)')
18]
19
20function setFeedFormatContentType (req: express.Request, res: express.Response, next: express.NextFunction) {
21 const format = req.query.format || req.params.format || 'rss'
22
23 let acceptableContentTypes: string[]
24 if (format === 'atom' || format === 'atom1') {
25 acceptableContentTypes = ['application/atom+xml', 'application/xml', 'text/xml']
26 } else if (format === 'json' || format === 'json1') {
27 acceptableContentTypes = ['application/json']
28 } else if (format === 'rss' || format === 'rss2') {
29 acceptableContentTypes = ['application/rss+xml', 'application/xml', 'text/xml']
30 } else {
31 acceptableContentTypes = ['application/xml', 'text/xml']
32 }
33
34 if (req.accepts(acceptableContentTypes)) {
35 res.set('Content-Type', req.accepts(acceptableContentTypes) as string)
36 } else {
37 return res.status(406).send({
38 message: `You should accept at least one of the following content-types: ${acceptableContentTypes.join(', ')}`
39 }).end()
40 }
41
42 return next()
43}
44
45const videoFeedsValidator = [
18 query('accountId').optional().custom(isIdValid), 46 query('accountId').optional().custom(isIdValid),
19 query('accountName').optional(), 47 query('accountName').optional(),
20 query('videoChannelId').optional().custom(isIdValid), 48 query('videoChannelId').optional().custom(isIdValid),
@@ -35,8 +63,6 @@ const videoFeedsValidator = [
35] 63]
36 64
37const videoCommentsFeedsValidator = [ 65const videoCommentsFeedsValidator = [
38 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
39 query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
40 query('videoId').optional().custom(isIdOrUUIDValid), 66 query('videoId').optional().custom(isIdOrUUIDValid),
41 67
42 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 68 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -53,6 +79,8 @@ const videoCommentsFeedsValidator = [
53// --------------------------------------------------------------------------- 79// ---------------------------------------------------------------------------
54 80
55export { 81export {
82 feedsFormatValidator,
83 setFeedFormatContentType,
56 videoFeedsValidator, 84 videoFeedsValidator,
57 videoCommentsFeedsValidator 85 videoCommentsFeedsValidator
58} 86}