]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/redundancy.ts
Cleanup useless express validator messages
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / redundancy.ts
index 3d557048a63b06fe5be26d58eacfc078838e4d38..a74772bd198c9ca26d5f96393f6c3750ca1e4aba 100644 (file)
@@ -1,24 +1,32 @@
-import * as express from 'express'
+import express from 'express'
 import { body, param, query } from 'express-validator'
-import { exists, isBooleanValid, isIdOrUUIDValid, isIdValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
+import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies'
+import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
+import {
+  exists,
+  isBooleanValid,
+  isIdOrUUIDValid,
+  isIdValid,
+  toBooleanOrNull,
+  toCompleteUUID,
+  toIntOrNull
+} from '../../helpers/custom-validators/misc'
+import { isHostValid } from '../../helpers/custom-validators/servers'
 import { logger } from '../../helpers/logger'
-import { areValidationErrors } from './utils'
 import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
-import { isHostValid } from '../../helpers/custom-validators/servers'
 import { ServerModel } from '../../models/server/server'
-import { doesVideoExist } from '../../helpers/middlewares'
-import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies'
-import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
+import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from './shared'
 
 const videoFileRedundancyGetValidator = [
-  param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
+  isValidVideoIdParam('videoId'),
+
   param('resolution')
     .customSanitizer(toIntOrNull)
-    .custom(exists).withMessage('Should have a valid resolution'),
+    .custom(exists),
   param('fps')
     .optional()
     .customSanitizer(toIntOrNull)
-    .custom(exists).withMessage('Should have a valid fps'),
+    .custom(exists),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking videoFileRedundancyGetValidator parameters', { parameters: req.params })
@@ -57,12 +65,11 @@ const videoFileRedundancyGetValidator = [
 ]
 
 const videoPlaylistRedundancyGetValidator = [
-  param('videoId')
-    .custom(isIdOrUUIDValid)
-    .not().isEmpty().withMessage('Should have a valid video id'),
+  isValidVideoIdParam('videoId'),
+
   param('streamingPlaylistType')
     .customSanitizer(toIntOrNull)
-    .custom(exists).withMessage('Should have a valid streaming playlist type'),
+    .custom(exists),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params })
@@ -97,10 +104,12 @@ const videoPlaylistRedundancyGetValidator = [
 ]
 
 const updateServerRedundancyValidator = [
-  param('host').custom(isHostValid).withMessage('Should have a valid host'),
+  param('host')
+    .custom(isHostValid),
+
   body('redundancyAllowed')
     .customSanitizer(toBooleanOrNull)
-    .custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'),
+    .custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed boolean'),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking updateServerRedundancy parameters', { parameters: req.params })
@@ -123,7 +132,7 @@ const updateServerRedundancyValidator = [
 
 const listVideoRedundanciesValidator = [
   query('target')
-    .custom(isVideoRedundancyTarget).withMessage('Should have a valid video redundancies target'),
+    .custom(isVideoRedundancyTarget),
 
   (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking listVideoRedundanciesValidator parameters', { parameters: req.query })
@@ -136,8 +145,8 @@ const listVideoRedundanciesValidator = [
 
 const addVideoRedundancyValidator = [
   body('videoId')
-    .custom(isIdValid)
-    .withMessage('Should have a valid video id'),
+    .customSanitizer(toCompleteUUID)
+    .custom(isIdOrUUIDValid),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking addVideoRedundancyValidator parameters', { parameters: req.query })
@@ -168,8 +177,7 @@ const addVideoRedundancyValidator = [
 
 const removeVideoRedundancyValidator = [
   param('redundancyId')
-    .custom(isIdValid)
-    .withMessage('Should have a valid redundancy id'),
+    .custom(isIdValid),
 
   async (req: express.Request, res: express.Response, next: express.NextFunction) => {
     logger.debug('Checking removeVideoRedundancyValidator parameters', { parameters: req.query })