aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/redundancy.ts
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/redundancy.ts
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/redundancy.ts')
-rw-r--r--server/middlewares/validators/redundancy.ts23
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'
2import { body, param, query } from 'express-validator' 2import { body, param, query } from 'express-validator'
3import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' 3import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc' 5import {
6 exists,
7 isBooleanValid,
8 isIdOrUUIDValid,
9 isIdValid,
10 toBooleanOrNull,
11 toCompleteUUID,
12 toIntOrNull
13} from '../../helpers/custom-validators/misc'
6import { isHostValid } from '../../helpers/custom-validators/servers' 14import { isHostValid } from '../../helpers/custom-validators/servers'
7import { logger } from '../../helpers/logger' 15import { logger } from '../../helpers/logger'
8import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' 16import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
9import { ServerModel } from '../../models/server/server' 17import { ServerModel } from '../../models/server/server'
10import { areValidationErrors, doesVideoExist } from './shared' 18import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from './shared'
11 19
12const videoFileRedundancyGetValidator = [ 20const 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
58const videoPlaylistRedundancyGetValidator = [ 67const 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
136const addVideoRedundancyValidator = [ 144const 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) => {