From d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 28 Jun 2021 17:30:59 +0200 Subject: Support short uuid for GET video/playlist --- server/middlewares/validators/shared/utils.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'server/middlewares/validators/shared') 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 @@ import * as express from 'express' -import { query, validationResult } from 'express-validator' +import { param, query, validationResult } from 'express-validator' +import { isIdOrUUIDValid, toCompleteUUID } from '@server/helpers/custom-validators/misc' import { logger } from '../../../helpers/logger' function areValidationErrors (req: express.Request, res: express.Response) { @@ -41,10 +42,24 @@ function createSortableColumns (sortableColumns: string[]) { return sortableColumns.concat(sortableColumnDesc) } +function isValidVideoIdParam (paramName: string) { + return param(paramName) + .customSanitizer(toCompleteUUID) + .custom(isIdOrUUIDValid).withMessage('Should have a valid video id') +} + +function isValidPlaylistIdParam (paramName: string) { + return param(paramName) + .customSanitizer(toCompleteUUID) + .custom(isIdOrUUIDValid).withMessage('Should have a valid playlist id') +} + // --------------------------------------------------------------------------- export { areValidationErrors, checkSort, - createSortableColumns + createSortableColumns, + isValidVideoIdParam, + isValidPlaylistIdParam } -- cgit v1.2.3