aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-28 17:30:59 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-06-29 14:56:35 +0200
commitd4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb (patch)
treea4cb07318100031951c3dffc61f4f2cb95d2cbd0 /server/middlewares/validators/shared
parent62ddc31a9e4b92d7d27898ccfc363f68ab044139 (diff)
downloadPeerTube-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.ts19
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query, validationResult } from 'express-validator' 2import { param, query, validationResult } from 'express-validator'
3import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc'
3import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
4 5
5function areValidationErrors (req: express.Request, res: express.Response) { 6function 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
45function isValidVideoIdParam (paramName: string) {
46 return param(paramName)
47 .customSanitizer(toCompleteUUID)
48 .custom(isIdOrUUIDValid).withMessage('Should have a valid video id')
49}
50
51function 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
46export { 59export {
47 areValidationErrors, 60 areValidationErrors,
48 checkSort, 61 checkSort,
49 createSortableColumns 62 createSortableColumns,
63 isValidVideoIdParam,
64 isValidPlaylistIdParam
50} 65}