diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-28 17:30:59 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-06-29 14:56:35 +0200 |
commit | d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb (patch) | |
tree | a4cb07318100031951c3dffc61f4f2cb95d2cbd0 /server/middlewares/validators/redundancy.ts | |
parent | 62ddc31a9e4b92d7d27898ccfc363f68ab044139 (diff) | |
download | PeerTube-d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb.tar.gz PeerTube-d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb.tar.zst PeerTube-d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb.zip |
Support short uuid for GET video/playlist
Diffstat (limited to 'server/middlewares/validators/redundancy.ts')
-rw-r--r-- | server/middlewares/validators/redundancy.ts | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts index da24f4c9b..116c8c611 100644 --- a/server/middlewares/validators/redundancy.ts +++ b/server/middlewares/validators/redundancy.ts | |||
@@ -2,15 +2,24 @@ import * as express from 'express' | |||
2 | import { body, param, query } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' | 3 | import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
5 | import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' | 5 | import { |
6 | exists, | ||
7 | isBooleanValid, | ||
8 | isIdOrUUIDValid, | ||
9 | isIdValid, | ||
10 | toBooleanOrNull, | ||
11 | toCompleteUUID, | ||
12 | toIntOrNull | ||
13 | } from '../../helpers/custom-validators/misc' | ||
6 | import { isHostValid } from '../../helpers/custom-validators/servers' | 14 | import { isHostValid } from '../../helpers/custom-validators/servers' |
7 | import { logger } from '../../helpers/logger' | 15 | import { logger } from '../../helpers/logger' |
8 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' | 16 | import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' |
9 | import { ServerModel } from '../../models/server/server' | 17 | import { ServerModel } from '../../models/server/server' |
10 | import { areValidationErrors, doesVideoExist } from './shared' | 18 | import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from './shared' |
11 | 19 | ||
12 | const videoFileRedundancyGetValidator = [ | 20 | const videoFileRedundancyGetValidator = [ |
13 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), | 21 | isValidVideoIdParam('videoId'), |
22 | |||
14 | param('resolution') | 23 | param('resolution') |
15 | .customSanitizer(toIntOrNull) | 24 | .customSanitizer(toIntOrNull) |
16 | .custom(exists).withMessage('Should have a valid resolution'), | 25 | .custom(exists).withMessage('Should have a valid resolution'), |
@@ -56,9 +65,8 @@ const videoFileRedundancyGetValidator = [ | |||
56 | ] | 65 | ] |
57 | 66 | ||
58 | const videoPlaylistRedundancyGetValidator = [ | 67 | const videoPlaylistRedundancyGetValidator = [ |
59 | param('videoId') | 68 | isValidVideoIdParam('videoId'), |
60 | .custom(isIdOrUUIDValid) | 69 | |
61 | .not().isEmpty().withMessage('Should have a valid video id'), | ||
62 | param('streamingPlaylistType') | 70 | param('streamingPlaylistType') |
63 | .customSanitizer(toIntOrNull) | 71 | .customSanitizer(toIntOrNull) |
64 | .custom(exists).withMessage('Should have a valid streaming playlist type'), | 72 | .custom(exists).withMessage('Should have a valid streaming playlist type'), |
@@ -135,7 +143,8 @@ const listVideoRedundanciesValidator = [ | |||
135 | 143 | ||
136 | const addVideoRedundancyValidator = [ | 144 | const addVideoRedundancyValidator = [ |
137 | body('videoId') | 145 | body('videoId') |
138 | .custom(isIdValid) | 146 | .customSanitizer(toCompleteUUID) |
147 | .custom(isIdOrUUIDValid) | ||
139 | .withMessage('Should have a valid video id'), | 148 | .withMessage('Should have a valid video id'), |
140 | 149 | ||
141 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 150 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |