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/shared | |
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/shared')
-rw-r--r-- | server/middlewares/validators/shared/utils.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/server/middlewares/validators/shared/utils.ts b/server/middlewares/validators/shared/utils.ts index d3e4870a9..4f08560af 100644 --- a/server/middlewares/validators/shared/utils.ts +++ b/server/middlewares/validators/shared/utils.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { query, validationResult } from 'express-validator' | 2 | import { param, query, validationResult } from 'express-validator' |
3 | import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' | ||
3 | import { logger } from '../../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
4 | 5 | ||
5 | function areValidationErrors (req: express.Request, res: express.Response) { | 6 | function areValidationErrors (req: express.Request, res: express.Response) { |
@@ -41,10 +42,24 @@ function createSortableColumns (sortableColumns: string[]) { | |||
41 | return sortableColumns.concat(sortableColumnDesc) | 42 | return sortableColumns.concat(sortableColumnDesc) |
42 | } | 43 | } |
43 | 44 | ||
45 | function isValidVideoIdParam (paramName: string) { | ||
46 | return param(paramName) | ||
47 | .customSanitizer(toCompleteUUID) | ||
48 | .custom(isIdOrUUIDValid).withMessage('Should have a valid video id') | ||
49 | } | ||
50 | |||
51 | function isValidPlaylistIdParam (paramName: string) { | ||
52 | return param(paramName) | ||
53 | .customSanitizer(toCompleteUUID) | ||
54 | .custom(isIdOrUUIDValid).withMessage('Should have a valid playlist id') | ||
55 | } | ||
56 | |||
44 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
45 | 58 | ||
46 | export { | 59 | export { |
47 | areValidationErrors, | 60 | areValidationErrors, |
48 | checkSort, | 61 | checkSort, |
49 | createSortableColumns | 62 | createSortableColumns, |
63 | isValidVideoIdParam, | ||
64 | isValidPlaylistIdParam | ||
50 | } | 65 | } |