Cleanup useless express validator messages

This commit is contained in:
Chocobozzz 2022-08-17 14:27:04 +02:00
parent 97eba003a9
commit 396f6f0140
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
43 changed files with 493 additions and 400 deletions

View File

@ -22,41 +22,34 @@ import { areValidationErrors, doesAbuseExist, doesAccountIdExist, doesCommentIdE
const abuseReportValidator = [ const abuseReportValidator = [
body('account.id') body('account.id')
.optional() .optional()
.custom(isIdValid) .custom(isIdValid),
.withMessage('Should have a valid accountId'),
body('video.id') body('video.id')
.optional() .optional()
.customSanitizer(toCompleteUUID) .customSanitizer(toCompleteUUID)
.custom(isIdOrUUIDValid) .custom(isIdOrUUIDValid),
.withMessage('Should have a valid videoId'),
body('video.startAt') body('video.startAt')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isAbuseTimestampValid) .custom(isAbuseTimestampValid),
.withMessage('Should have valid starting time value'),
body('video.endAt') body('video.endAt')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isAbuseTimestampValid) .custom(isAbuseTimestampValid)
.withMessage('Should have valid ending time value')
.bail() .bail()
.custom(isAbuseTimestampCoherent) .custom(isAbuseTimestampCoherent)
.withMessage('Should have a startAt timestamp beginning before endAt'), .withMessage('Should have a startAt timestamp beginning before endAt'),
body('comment.id') body('comment.id')
.optional() .optional()
.custom(isIdValid) .custom(isIdValid),
.withMessage('Should have a valid commentId'),
body('reason') body('reason')
.custom(isAbuseReasonValid) .custom(isAbuseReasonValid),
.withMessage('Should have a valid reason'),
body('predefinedReasons') body('predefinedReasons')
.optional() .optional()
.custom(areAbusePredefinedReasonsValid) .custom(areAbusePredefinedReasonsValid),
.withMessage('Should have a valid list of predefined reasons'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking abuseReport parameters', { parameters: req.body }) logger.debug('Checking abuseReport parameters', { parameters: req.body })
@ -79,7 +72,8 @@ const abuseReportValidator = [
] ]
const abuseGetValidator = [ const abuseGetValidator = [
param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), param('id')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking abuseGetValidator parameters', { parameters: req.body }) logger.debug('Checking abuseGetValidator parameters', { parameters: req.body })
@ -92,14 +86,15 @@ const abuseGetValidator = [
] ]
const abuseUpdateValidator = [ const abuseUpdateValidator = [
param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), param('id')
.custom(isIdValid),
body('state') body('state')
.optional() .optional()
.custom(isAbuseStateValid).withMessage('Should have a valid abuse state'), .custom(isAbuseStateValid),
body('moderationComment') body('moderationComment')
.optional() .optional()
.custom(isAbuseModerationCommentValid).withMessage('Should have a valid moderation comment'), .custom(isAbuseModerationCommentValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking abuseUpdateValidator parameters', { parameters: req.body }) logger.debug('Checking abuseUpdateValidator parameters', { parameters: req.body })
@ -114,36 +109,34 @@ const abuseUpdateValidator = [
const abuseListForAdminsValidator = [ const abuseListForAdminsValidator = [
query('id') query('id')
.optional() .optional()
.custom(isIdValid).withMessage('Should have a valid id'), .custom(isIdValid),
query('filter') query('filter')
.optional() .optional()
.custom(isAbuseFilterValid) .custom(isAbuseFilterValid),
.withMessage('Should have a valid filter'),
query('predefinedReason') query('predefinedReason')
.optional() .optional()
.custom(isAbusePredefinedReasonValid) .custom(isAbusePredefinedReasonValid),
.withMessage('Should have a valid predefinedReason'),
query('search') query('search')
.optional() .optional()
.custom(exists).withMessage('Should have a valid search'), .custom(exists),
query('state') query('state')
.optional() .optional()
.custom(isAbuseStateValid).withMessage('Should have a valid abuse state'), .custom(isAbuseStateValid),
query('videoIs') query('videoIs')
.optional() .optional()
.custom(isAbuseVideoIsValid).withMessage('Should have a valid "video is" attribute'), .custom(isAbuseVideoIsValid),
query('searchReporter') query('searchReporter')
.optional() .optional()
.custom(exists).withMessage('Should have a valid reporter search'), .custom(exists),
query('searchReportee') query('searchReportee')
.optional() .optional()
.custom(exists).withMessage('Should have a valid reportee search'), .custom(exists),
query('searchVideo') query('searchVideo')
.optional() .optional()
.custom(exists).withMessage('Should have a valid video search'), .custom(exists),
query('searchVideoChannel') query('searchVideoChannel')
.optional() .optional()
.custom(exists).withMessage('Should have a valid video channel search'), .custom(exists),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking abuseListForAdminsValidator parameters', { parameters: req.body }) logger.debug('Checking abuseListForAdminsValidator parameters', { parameters: req.body })
@ -157,15 +150,15 @@ const abuseListForAdminsValidator = [
const abuseListForUserValidator = [ const abuseListForUserValidator = [
query('id') query('id')
.optional() .optional()
.custom(isIdValid).withMessage('Should have a valid id'), .custom(isIdValid),
query('search') query('search')
.optional() .optional()
.custom(exists).withMessage('Should have a valid search'), .custom(exists),
query('state') query('state')
.optional() .optional()
.custom(isAbuseStateValid).withMessage('Should have a valid abuse state'), .custom(isAbuseStateValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking abuseListForUserValidator parameters', { parameters: req.body }) logger.debug('Checking abuseListForUserValidator parameters', { parameters: req.body })
@ -177,7 +170,8 @@ const abuseListForUserValidator = [
] ]
const getAbuseValidator = [ const getAbuseValidator = [
param('id').custom(isIdValid).not().isEmpty().withMessage('Should have a valid id'), param('id')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking getAbuseValidator parameters', { parameters: req.body }) logger.debug('Checking getAbuseValidator parameters', { parameters: req.body })
@ -216,7 +210,8 @@ const checkAbuseValidForMessagesValidator = [
] ]
const addAbuseMessageValidator = [ const addAbuseMessageValidator = [
body('message').custom(isAbuseMessageValid).not().isEmpty().withMessage('Should have a valid abuse message'), body('message')
.custom(isAbuseMessageValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking addAbuseMessageValidator parameters', { parameters: req.body }) logger.debug('Checking addAbuseMessageValidator parameters', { parameters: req.body })
@ -228,7 +223,8 @@ const addAbuseMessageValidator = [
] ]
const deleteAbuseMessageValidator = [ const deleteAbuseMessageValidator = [
param('messageId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid message id'), param('messageId')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking deleteAbuseMessageValidator parameters', { parameters: req.body }) logger.debug('Checking deleteAbuseMessageValidator parameters', { parameters: req.body })

View File

@ -5,7 +5,8 @@ import { logger } from '../../helpers/logger'
import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared' import { areValidationErrors, doesAccountNameWithHostExist, doesLocalAccountNameExist } from './shared'
const localAccountValidator = [ const localAccountValidator = [
param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), param('name')
.custom(isAccountNameValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
@ -18,7 +19,8 @@ const localAccountValidator = [
] ]
const accountNameWithHostGetValidator = [ const accountNameWithHostGetValidator = [
param('accountName').exists().withMessage('Should have an account name with host'), param('accountName')
.exists(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params }) logger.debug('Checking accountsNameWithHostGetValidator parameters', { parameters: req.params })

View File

@ -7,7 +7,7 @@ import { areValidationErrors } from '../shared'
const apPaginationValidator = [ const apPaginationValidator = [
query('page') query('page')
.optional() .optional()
.isInt({ min: 1 }).withMessage('Should have a valid page number'), .isInt({ min: 1 }),
query('size') query('size')
.optional() .optional()
.isInt({ min: 0, max: PAGINATION.OUTBOX.COUNT.MAX }).withMessage(`Should have a valid page size (max: ${PAGINATION.OUTBOX.COUNT.MAX})`), .isInt({ min: 0, max: PAGINATION.OUTBOX.COUNT.MAX }).withMessage(`Should have a valid page size (max: ${PAGINATION.OUTBOX.COUNT.MAX})`),

View File

@ -12,16 +12,16 @@ import { areValidationErrors } from '../shared'
const signatureValidator = [ const signatureValidator = [
body('signature.type') body('signature.type')
.optional() .optional()
.custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), .custom(isSignatureTypeValid),
body('signature.created') body('signature.created')
.optional() .optional()
.custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'), .custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'),
body('signature.creator') body('signature.creator')
.optional() .optional()
.custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), .custom(isSignatureCreatorValid),
body('signature.signatureValue') body('signature.signatureValue')
.optional() .optional()
.custom(isSignatureValueValid).withMessage('Should have a valid signature value'), .custom(isSignatureValueValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking Linked Data Signature parameter', { parameters: { signature: req.body.signature } }) logger.debug('Checking Linked Data Signature parameter', { parameters: { signature: req.body.signature } })

View File

@ -13,7 +13,8 @@ import { ServerBlocklistModel } from '../../models/server/server-blocklist'
import { areValidationErrors, doesAccountNameWithHostExist } from './shared' import { areValidationErrors, doesAccountNameWithHostExist } from './shared'
const blockAccountValidator = [ const blockAccountValidator = [
body('accountName').exists().withMessage('Should have an account name with host'), body('accountName')
.exists(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking blockAccountByAccountValidator parameters', { parameters: req.body }) logger.debug('Checking blockAccountByAccountValidator parameters', { parameters: req.body })
@ -37,7 +38,8 @@ const blockAccountValidator = [
] ]
const unblockAccountByAccountValidator = [ const unblockAccountByAccountValidator = [
param('accountName').exists().withMessage('Should have an account name with host'), param('accountName')
.exists(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking unblockAccountByAccountValidator parameters', { parameters: req.params }) logger.debug('Checking unblockAccountByAccountValidator parameters', { parameters: req.params })
@ -54,7 +56,8 @@ const unblockAccountByAccountValidator = [
] ]
const unblockAccountByServerValidator = [ const unblockAccountByServerValidator = [
param('accountName').exists().withMessage('Should have an account name with host'), param('accountName')
.exists(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params }) logger.debug('Checking unblockAccountByServerValidator parameters', { parameters: req.params })
@ -71,7 +74,8 @@ const unblockAccountByServerValidator = [
] ]
const blockServerValidator = [ const blockServerValidator = [
body('host').custom(isHostValid).withMessage('Should have a valid host'), body('host')
.custom(isHostValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking serverGetValidator parameters', { parameters: req.body }) logger.debug('Checking serverGetValidator parameters', { parameters: req.body })
@ -96,7 +100,8 @@ const blockServerValidator = [
] ]
const unblockServerByAccountValidator = [ const unblockServerByAccountValidator = [
param('host').custom(isHostValid).withMessage('Should have an account name with host'), param('host')
.custom(isHostValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking unblockServerByAccountValidator parameters', { parameters: req.params }) logger.debug('Checking unblockServerByAccountValidator parameters', { parameters: req.params })
@ -111,7 +116,8 @@ const unblockServerByAccountValidator = [
] ]
const unblockServerByServerValidator = [ const unblockServerByServerValidator = [
param('host').custom(isHostValid).withMessage('Should have an account name with host'), param('host')
.custom(isHostValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking unblockServerByServerValidator parameters', { parameters: req.params }) logger.debug('Checking unblockServerByServerValidator parameters', { parameters: req.params })

View File

@ -7,9 +7,10 @@ import { logger } from '../../helpers/logger'
import { areValidationErrors, doesAccountNameWithHostExist } from './shared' import { areValidationErrors, doesAccountNameWithHostExist } from './shared'
const bulkRemoveCommentsOfValidator = [ const bulkRemoveCommentsOfValidator = [
body('accountName').exists().withMessage('Should have an account name with host'), body('accountName')
.exists(),
body('scope') body('scope')
.custom(isBulkRemoveCommentsOfScopeValid).withMessage('Should have a valid scope'), .custom(isBulkRemoveCommentsOfScopeValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking bulkRemoveCommentsOfValidator parameters', { parameters: req.body }) logger.debug('Checking bulkRemoveCommentsOfValidator parameters', { parameters: req.body })

View File

@ -11,100 +11,98 @@ import { areValidationErrors } from './shared'
import { HttpStatusCode } from '@shared/models/http/http-error-codes' import { HttpStatusCode } from '@shared/models/http/http-error-codes'
const customConfigUpdateValidator = [ const customConfigUpdateValidator = [
body('instance.name').exists().withMessage('Should have a valid instance name'), body('instance.name').exists(),
body('instance.shortDescription').exists().withMessage('Should have a valid instance short description'), body('instance.shortDescription').exists(),
body('instance.description').exists().withMessage('Should have a valid instance description'), body('instance.description').exists(),
body('instance.terms').exists().withMessage('Should have a valid instance terms'), body('instance.terms').exists(),
body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid).withMessage('Should have a valid NSFW policy'), body('instance.defaultNSFWPolicy').custom(isUserNSFWPolicyValid),
body('instance.defaultClientRoute').exists().withMessage('Should have a valid instance default client route'), body('instance.defaultClientRoute').exists(),
body('instance.customizations.css').exists().withMessage('Should have a valid instance CSS customization'), body('instance.customizations.css').exists(),
body('instance.customizations.javascript').exists().withMessage('Should have a valid instance JavaScript customization'), body('instance.customizations.javascript').exists(),
body('services.twitter.username').exists().withMessage('Should have a valid twitter username'), body('services.twitter.username').exists(),
body('services.twitter.whitelisted').isBoolean().withMessage('Should have a valid twitter whitelisted boolean'), body('services.twitter.whitelisted').isBoolean(),
body('cache.previews.size').isInt().withMessage('Should have a valid previews cache size'), body('cache.previews.size').isInt(),
body('cache.captions.size').isInt().withMessage('Should have a valid captions cache size'), body('cache.captions.size').isInt(),
body('cache.torrents.size').isInt().withMessage('Should have a valid torrents cache size'), body('cache.torrents.size').isInt(),
body('signup.enabled').isBoolean().withMessage('Should have a valid signup enabled boolean'), body('signup.enabled').isBoolean(),
body('signup.limit').isInt().withMessage('Should have a valid signup limit'), body('signup.limit').isInt(),
body('signup.requiresEmailVerification').isBoolean().withMessage('Should have a valid requiresEmailVerification boolean'), body('signup.requiresEmailVerification').isBoolean(),
body('signup.minimumAge').isInt().withMessage('Should have a valid minimum age required'), body('signup.minimumAge').isInt(),
body('admin.email').isEmail().withMessage('Should have a valid administrator email'), body('admin.email').isEmail(),
body('contactForm.enabled').isBoolean().withMessage('Should have a valid contact form enabled boolean'), body('contactForm.enabled').isBoolean(),
body('user.videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid video quota'), body('user.videoQuota').custom(isUserVideoQuotaValid),
body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily video quota'), body('user.videoQuotaDaily').custom(isUserVideoQuotaDailyValid),
body('videoChannels.maxPerUser').isInt().withMessage('Should have a valid maximum amount of video channels per user'), body('videoChannels.maxPerUser').isInt(),
body('transcoding.enabled').isBoolean().withMessage('Should have a valid transcoding enabled boolean'), body('transcoding.enabled').isBoolean(),
body('transcoding.allowAdditionalExtensions').isBoolean().withMessage('Should have a valid additional extensions boolean'), body('transcoding.allowAdditionalExtensions').isBoolean(),
body('transcoding.threads').isInt().withMessage('Should have a valid transcoding threads number'), body('transcoding.threads').isInt(),
body('transcoding.concurrency').isInt({ min: 1 }).withMessage('Should have a valid transcoding concurrency number'), body('transcoding.concurrency').isInt({ min: 1 }),
body('transcoding.resolutions.0p').isBoolean().withMessage('Should have a valid transcoding 0p resolution enabled boolean'), body('transcoding.resolutions.0p').isBoolean(),
body('transcoding.resolutions.144p').isBoolean().withMessage('Should have a valid transcoding 144p resolution enabled boolean'), body('transcoding.resolutions.144p').isBoolean(),
body('transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'), body('transcoding.resolutions.240p').isBoolean(),
body('transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'), body('transcoding.resolutions.360p').isBoolean(),
body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), body('transcoding.resolutions.480p').isBoolean(),
body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), body('transcoding.resolutions.720p').isBoolean(),
body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), body('transcoding.resolutions.1080p').isBoolean(),
body('transcoding.resolutions.1440p').isBoolean().withMessage('Should have a valid transcoding 1440p resolution enabled boolean'), body('transcoding.resolutions.1440p').isBoolean(),
body('transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'), body('transcoding.resolutions.2160p').isBoolean(),
body('transcoding.alwaysTranscodeOriginalResolution').isBoolean() body('transcoding.alwaysTranscodeOriginalResolution').isBoolean(),
.withMessage('Should have a valid always transcode original resolution boolean'),
body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'), body('transcoding.webtorrent.enabled').isBoolean(),
body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'), body('transcoding.hls.enabled').isBoolean(),
body('videoStudio.enabled').isBoolean().withMessage('Should have a valid video studio enabled boolean'), body('videoStudio.enabled').isBoolean(),
body('import.videos.concurrency').isInt({ min: 0 }).withMessage('Should have a valid import concurrency number'), body('import.videos.concurrency').isInt({ min: 0 }),
body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'), body('import.videos.http.enabled').isBoolean(),
body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'), body('import.videos.torrent.enabled').isBoolean(),
body('import.videoChannelSynchronization.enabled').isBoolean().withMessage('Should have a valid synchronization enabled boolean'), body('import.videoChannelSynchronization.enabled').isBoolean(),
body('trending.videos.algorithms.default').exists().withMessage('Should have a valid default trending algorithm'), body('trending.videos.algorithms.default').exists(),
body('trending.videos.algorithms.enabled').exists().withMessage('Should have a valid array of enabled trending algorithms'), body('trending.videos.algorithms.enabled').exists(),
body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), body('followers.instance.enabled').isBoolean(),
body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), body('followers.instance.manualApproval').isBoolean(),
body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)),
body('broadcastMessage.enabled').isBoolean().withMessage('Should have a valid broadcast message enabled boolean'), body('broadcastMessage.enabled').isBoolean(),
body('broadcastMessage.message').exists().withMessage('Should have a valid broadcast message'), body('broadcastMessage.message').exists(),
body('broadcastMessage.level').exists().withMessage('Should have a valid broadcast level'), body('broadcastMessage.level').exists(),
body('broadcastMessage.dismissable').isBoolean().withMessage('Should have a valid broadcast dismissable boolean'), body('broadcastMessage.dismissable').isBoolean(),
body('live.enabled').isBoolean().withMessage('Should have a valid live enabled boolean'), body('live.enabled').isBoolean(),
body('live.allowReplay').isBoolean().withMessage('Should have a valid live allow replay boolean'), body('live.allowReplay').isBoolean(),
body('live.maxDuration').isInt().withMessage('Should have a valid live max duration'), body('live.maxDuration').isInt(),
body('live.maxInstanceLives').custom(isIntOrNull).withMessage('Should have a valid max instance lives'), body('live.maxInstanceLives').custom(isIntOrNull),
body('live.maxUserLives').custom(isIntOrNull).withMessage('Should have a valid max user lives'), body('live.maxUserLives').custom(isIntOrNull),
body('live.transcoding.enabled').isBoolean().withMessage('Should have a valid live transcoding enabled boolean'), body('live.transcoding.enabled').isBoolean(),
body('live.transcoding.threads').isInt().withMessage('Should have a valid live transcoding threads'), body('live.transcoding.threads').isInt(),
body('live.transcoding.resolutions.144p').isBoolean().withMessage('Should have a valid transcoding 144p resolution enabled boolean'), body('live.transcoding.resolutions.144p').isBoolean(),
body('live.transcoding.resolutions.240p').isBoolean().withMessage('Should have a valid transcoding 240p resolution enabled boolean'), body('live.transcoding.resolutions.240p').isBoolean(),
body('live.transcoding.resolutions.360p').isBoolean().withMessage('Should have a valid transcoding 360p resolution enabled boolean'), body('live.transcoding.resolutions.360p').isBoolean(),
body('live.transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), body('live.transcoding.resolutions.480p').isBoolean(),
body('live.transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), body('live.transcoding.resolutions.720p').isBoolean(),
body('live.transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), body('live.transcoding.resolutions.1080p').isBoolean(),
body('live.transcoding.resolutions.1440p').isBoolean().withMessage('Should have a valid transcoding 1440p resolution enabled boolean'), body('live.transcoding.resolutions.1440p').isBoolean(),
body('live.transcoding.resolutions.2160p').isBoolean().withMessage('Should have a valid transcoding 2160p resolution enabled boolean'), body('live.transcoding.resolutions.2160p').isBoolean(),
body('live.transcoding.alwaysTranscodeOriginalResolution').isBoolean() body('live.transcoding.alwaysTranscodeOriginalResolution').isBoolean(),
.withMessage('Should have a valid always transcode live original resolution boolean'),
body('search.remoteUri.users').isBoolean().withMessage('Should have a remote URI search for users boolean'), body('search.remoteUri.users').isBoolean(),
body('search.remoteUri.anonymous').isBoolean().withMessage('Should have a valid remote URI search for anonymous boolean'), body('search.remoteUri.anonymous').isBoolean(),
body('search.searchIndex.enabled').isBoolean().withMessage('Should have a valid search index enabled boolean'), body('search.searchIndex.enabled').isBoolean(),
body('search.searchIndex.url').exists().withMessage('Should have a valid search index URL'), body('search.searchIndex.url').exists(),
body('search.searchIndex.disableLocalSearch').isBoolean().withMessage('Should have a valid search index disable local search boolean'), body('search.searchIndex.disableLocalSearch').isBoolean(),
body('search.searchIndex.isDefaultSearch').isBoolean().withMessage('Should have a valid search index default enabled boolean'), body('search.searchIndex.isDefaultSearch').isBoolean(),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })

View File

@ -16,8 +16,20 @@ import {
} from './shared' } from './shared'
const feedsFormatValidator = [ const feedsFormatValidator = [
param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), param('format')
query('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)') .optional()
.custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
query('format')
.optional()
.custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
(req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking feeds format parameters', { parameters: req.query })
if (areValidationErrors(req, res)) return
return next()
}
] ]
function setFeedFormatContentType (req: express.Request, res: express.Response, next: express.NextFunction) { function setFeedFormatContentType (req: express.Request, res: express.Response, next: express.NextFunction) {
@ -49,16 +61,14 @@ function setFeedFormatContentType (req: express.Request, res: express.Response,
const videoFeedsValidator = [ const videoFeedsValidator = [
query('accountId') query('accountId')
.optional() .optional()
.custom(isIdValid) .custom(isIdValid),
.withMessage('Should have a valid account id'),
query('accountName') query('accountName')
.optional(), .optional(),
query('videoChannelId') query('videoChannelId')
.optional() .optional()
.custom(isIdValid) .custom(isIdValid),
.withMessage('Should have a valid channel id'),
query('videoChannelName') query('videoChannelName')
.optional(), .optional(),
@ -79,12 +89,10 @@ const videoFeedsValidator = [
const videoSubscriptionFeedsValidator = [ const videoSubscriptionFeedsValidator = [
query('accountId') query('accountId')
.custom(isIdValid) .custom(isIdValid),
.withMessage('Should have a valid account id'),
query('token') query('token')
.custom(exists) .custom(exists),
.withMessage('Should have a token'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking subscription feeds parameters', { parameters: req.query }) logger.debug('Checking subscription feeds parameters', { parameters: req.query })
@ -100,8 +108,8 @@ const videoSubscriptionFeedsValidator = [
const videoCommentsFeedsValidator = [ const videoCommentsFeedsValidator = [
query('videoId') query('videoId')
.customSanitizer(toCompleteUUID)
.optional() .optional()
.customSanitizer(toCompleteUUID)
.custom(isIdOrUUIDValid), .custom(isIdOrUUIDValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {

View File

@ -19,10 +19,10 @@ import { areValidationErrors } from './shared'
const listFollowsValidator = [ const listFollowsValidator = [
query('state') query('state')
.optional() .optional()
.custom(isFollowStateValid).withMessage('Should have a valid follow state'), .custom(isFollowStateValid),
query('actorType') query('actorType')
.optional() .optional()
.custom(isActorTypeValid).withMessage('Should have a valid actor type'), .custom(isActorTypeValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return if (areValidationErrors(req, res)) return
@ -70,8 +70,7 @@ const followValidator = [
const removeFollowingValidator = [ const removeFollowingValidator = [
param('hostOrHandle') param('hostOrHandle')
.custom(value => isHostValid(value) || isRemoteHandleValid(value)) .custom(value => isHostValid(value) || isRemoteHandleValid(value)),
.withMessage('Should have a valid host/handle'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking unfollowing parameters', { parameters: req.params }) logger.debug('Checking unfollowing parameters', { parameters: req.params })
@ -100,7 +99,8 @@ const removeFollowingValidator = [
] ]
const getFollowerValidator = [ const getFollowerValidator = [
param('nameWithHost').custom(isValidActorHandle).withMessage('Should have a valid nameWithHost'), param('nameWithHost')
.custom(isValidActorHandle),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking get follower parameters', { parameters: req.params }) logger.debug('Checking get follower parameters', { parameters: req.params })

View File

@ -8,12 +8,12 @@ const lTags = loggerTagsFactory('validators', 'jobs')
const listJobsValidator = [ const listJobsValidator = [
param('state') param('state')
.optional() .optional()
.custom(isValidJobState).not().isEmpty().withMessage('Should have a valid job state'), .custom(isValidJobState),
query('jobType') query('jobType')
.optional() .optional()
.custom(isValidJobType).withMessage('Should have a valid job state'), .custom(isValidJobType),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking listJobsValidator parameters.', { parameters: req.params, ...lTags() }) logger.debug('Checking listJobsValidator parameters.', { parameters: req.params, ...lTags() })

View File

@ -18,25 +18,25 @@ import { areValidationErrors } from './shared'
const createClientLogValidator = [ const createClientLogValidator = [
body('message') body('message')
.custom(isValidClientLogMessage).withMessage('Should have a valid log message'), .custom(isValidClientLogMessage),
body('url') body('url')
.custom(isUrlValid).withMessage('Should have a valid log url'), .custom(isUrlValid),
body('level') body('level')
.custom(isValidClientLogLevel).withMessage('Should have a valid log message'), .custom(isValidClientLogLevel),
body('stackTrace') body('stackTrace')
.optional() .optional()
.custom(isValidClientLogStackTrace).withMessage('Should have a valid log stack trace'), .custom(isValidClientLogStackTrace),
body('meta') body('meta')
.optional() .optional()
.custom(isValidClientLogMeta).withMessage('Should have a valid log meta'), .custom(isValidClientLogMeta),
body('userAgent') body('userAgent')
.optional() .optional()
.custom(isValidClientLogUserAgent).withMessage('Should have a valid log user agent'), .custom(isValidClientLogUserAgent),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking createClientLogValidator parameters.', { parameters: req.query }) logger.debug('Checking createClientLogValidator parameters.', { parameters: req.query })
@ -56,7 +56,7 @@ const getLogsValidator = [
.custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'),
query('level') query('level')
.optional() .optional()
.custom(isValidLogLevel).withMessage('Should have a valid level'), .custom(isValidLogLevel),
query('tagsOneOf') query('tagsOneOf')
.optional() .optional()
.customSanitizer(toArray) .customSanitizer(toArray)

View File

@ -9,30 +9,29 @@ import { areValidationErrors, doesVideoExist } from './shared'
const addPlaybackMetricValidator = [ const addPlaybackMetricValidator = [
body('resolution') body('resolution')
.isInt({ min: 0 }).withMessage('Invalid resolution'), .isInt({ min: 0 }),
body('fps') body('fps')
.optional() .optional()
.isInt({ min: 0 }).withMessage('Invalid fps'), .isInt({ min: 0 }),
body('playerMode') body('playerMode')
.custom(isValidPlayerMode).withMessage('Invalid playerMode'), .custom(isValidPlayerMode),
body('resolutionChanges') body('resolutionChanges')
.isInt({ min: 0 }).withMessage('Invalid resolutionChanges'), .isInt({ min: 0 }),
body('errors') body('errors')
.isInt({ min: 0 }).withMessage('Invalid errors'), .isInt({ min: 0 }),
body('downloadedBytesP2P') body('downloadedBytesP2P')
.isInt({ min: 0 }).withMessage('Invalid downloadedBytesP2P'), .isInt({ min: 0 }),
body('downloadedBytesHTTP') body('downloadedBytesHTTP')
.isInt({ min: 0 }).withMessage('Invalid downloadedBytesHTTP'), .isInt({ min: 0 }),
body('uploadedBytesP2P') body('uploadedBytesP2P')
.isInt({ min: 0 }).withMessage('Invalid uploadedBytesP2P'), .isInt({ min: 0 }),
body('videoId') body('videoId')
.customSanitizer(toCompleteUUID) .customSanitizer(toCompleteUUID)
.optional()
.custom(isIdOrUUIDValid), .custom(isIdOrUUIDValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {

View File

@ -39,10 +39,17 @@ if (isTestOrDevInstance()) {
} }
const oembedValidator = [ const oembedValidator = [
query('url').isURL(isURLOptions).withMessage('Should have a valid url'), query('url')
query('maxwidth').optional().isInt().withMessage('Should have a valid max width'), .isURL(isURLOptions),
query('maxheight').optional().isInt().withMessage('Should have a valid max height'), query('maxwidth')
query('format').optional().isIn([ 'xml', 'json' ]).withMessage('Should have a valid format'), .optional()
.isInt(),
query('maxheight')
.optional()
.isInt(),
query('format')
.optional()
.isIn([ 'xml', 'json' ]),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking oembed parameters', { parameters: req.query }) logger.debug('Checking oembed parameters', { parameters: req.query })

View File

@ -10,7 +10,7 @@ function paginationValidatorBuilder (tags: string[] = []) {
return [ return [
query('start') query('start')
.optional() .optional()
.isInt({ min: 0 }).withMessage('Should have a number start'), .isInt({ min: 0 }),
query('count') query('count')
.optional() .optional()
.isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`), .isInt({ min: 0, max: PAGINATION.GLOBAL.COUNT.MAX }).withMessage(`Should have a number count (max: ${PAGINATION.GLOBAL.COUNT.MAX})`),

View File

@ -13,12 +13,14 @@ import { areValidationErrors } from './shared'
const getPluginValidator = (pluginType: PluginType, withVersion = true) => { const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
const validators: (ValidationChain | express.Handler)[] = [ const validators: (ValidationChain | express.Handler)[] = [
param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name') param('pluginName')
.custom(isPluginNameValid)
] ]
if (withVersion) { if (withVersion) {
validators.push( validators.push(
param('pluginVersion').custom(isPluginVersionValid).withMessage('Should have a valid plugin version') param('pluginVersion')
.custom(isPluginVersionValid)
) )
} }
@ -52,7 +54,8 @@ const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
} }
const getExternalAuthValidator = [ const getExternalAuthValidator = [
param('authName').custom(exists).withMessage('Should have a valid auth name'), param('authName')
.custom(exists),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking getExternalAuthValidator parameters', { parameters: req.params }) logger.debug('Checking getExternalAuthValidator parameters', { parameters: req.params })
@ -82,7 +85,8 @@ const getExternalAuthValidator = [
] ]
const pluginStaticDirectoryValidator = [ const pluginStaticDirectoryValidator = [
param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'), param('staticEndpoint')
.custom(isSafePath),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking pluginStaticDirectoryValidator parameters', { parameters: req.params }) logger.debug('Checking pluginStaticDirectoryValidator parameters', { parameters: req.params })
@ -97,11 +101,11 @@ const listPluginsValidator = [
query('pluginType') query('pluginType')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), .custom(isPluginTypeValid),
query('uninstalled') query('uninstalled')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'), .custom(isBooleanValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking listPluginsValidator parameters', { parameters: req.query }) logger.debug('Checking listPluginsValidator parameters', { parameters: req.query })
@ -115,13 +119,13 @@ const listPluginsValidator = [
const installOrUpdatePluginValidator = [ const installOrUpdatePluginValidator = [
body('npmName') body('npmName')
.optional() .optional()
.custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), .custom(isNpmPluginNameValid),
body('pluginVersion') body('pluginVersion')
.optional() .optional()
.custom(isPluginVersionValid).withMessage('Should have a valid plugin version'), .custom(isPluginVersionValid),
body('path') body('path')
.optional() .optional()
.custom(isSafePath).withMessage('Should have a valid safe path'), .custom(isSafePath),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking installOrUpdatePluginValidator parameters', { parameters: req.body }) logger.debug('Checking installOrUpdatePluginValidator parameters', { parameters: req.body })
@ -141,7 +145,8 @@ const installOrUpdatePluginValidator = [
] ]
const uninstallPluginValidator = [ const uninstallPluginValidator = [
body('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), body('npmName')
.custom(isNpmPluginNameValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking uninstallPluginValidator parameters', { parameters: req.body }) logger.debug('Checking uninstallPluginValidator parameters', { parameters: req.body })
@ -153,7 +158,8 @@ const uninstallPluginValidator = [
] ]
const existingPluginValidator = [ const existingPluginValidator = [
param('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid plugin name'), param('npmName')
.custom(isNpmPluginNameValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking enabledPluginValidator parameters', { parameters: req.params }) logger.debug('Checking enabledPluginValidator parameters', { parameters: req.params })
@ -174,7 +180,8 @@ const existingPluginValidator = [
] ]
const updatePluginSettingsValidator = [ const updatePluginSettingsValidator = [
body('settings').exists().withMessage('Should have settings'), body('settings')
.exists(),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking enabledPluginValidator parameters', { parameters: req.body }) logger.debug('Checking enabledPluginValidator parameters', { parameters: req.body })
@ -188,14 +195,14 @@ const updatePluginSettingsValidator = [
const listAvailablePluginsValidator = [ const listAvailablePluginsValidator = [
query('search') query('search')
.optional() .optional()
.exists().withMessage('Should have a valid search'), .exists(),
query('pluginType') query('pluginType')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), .custom(isPluginTypeValid),
query('currentPeerTubeEngine') query('currentPeerTubeEngine')
.optional() .optional()
.custom(isPluginVersionValid).withMessage('Should have a valid current peertube engine'), .custom(isPluginVersionValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking enabledPluginValidator parameters', { parameters: req.query }) logger.debug('Checking enabledPluginValidator parameters', { parameters: req.query })

View File

@ -22,11 +22,11 @@ const videoFileRedundancyGetValidator = [
param('resolution') param('resolution')
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(exists).withMessage('Should have a valid resolution'), .custom(exists),
param('fps') param('fps')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(exists).withMessage('Should have a valid fps'), .custom(exists),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoFileRedundancyGetValidator parameters', { parameters: req.params }) logger.debug('Checking videoFileRedundancyGetValidator parameters', { parameters: req.params })
@ -69,7 +69,7 @@ const videoPlaylistRedundancyGetValidator = [
param('streamingPlaylistType') param('streamingPlaylistType')
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(exists).withMessage('Should have a valid streaming playlist type'), .custom(exists),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params }) logger.debug('Checking videoPlaylistRedundancyGetValidator parameters', { parameters: req.params })
@ -104,10 +104,12 @@ const videoPlaylistRedundancyGetValidator = [
] ]
const updateServerRedundancyValidator = [ const updateServerRedundancyValidator = [
param('host').custom(isHostValid).withMessage('Should have a valid host'), param('host')
.custom(isHostValid),
body('redundancyAllowed') body('redundancyAllowed')
.customSanitizer(toBooleanOrNull) .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) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking updateServerRedundancy parameters', { parameters: req.params }) logger.debug('Checking updateServerRedundancy parameters', { parameters: req.params })
@ -130,7 +132,7 @@ const updateServerRedundancyValidator = [
const listVideoRedundanciesValidator = [ const listVideoRedundanciesValidator = [
query('target') query('target')
.custom(isVideoRedundancyTarget).withMessage('Should have a valid video redundancies target'), .custom(isVideoRedundancyTarget),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking listVideoRedundanciesValidator parameters', { parameters: req.query }) logger.debug('Checking listVideoRedundanciesValidator parameters', { parameters: req.query })
@ -144,8 +146,7 @@ const listVideoRedundanciesValidator = [
const addVideoRedundancyValidator = [ const addVideoRedundancyValidator = [
body('videoId') body('videoId')
.customSanitizer(toCompleteUUID) .customSanitizer(toCompleteUUID)
.custom(isIdOrUUIDValid) .custom(isIdOrUUIDValid),
.withMessage('Should have a valid video id'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking addVideoRedundancyValidator parameters', { parameters: req.query }) logger.debug('Checking addVideoRedundancyValidator parameters', { parameters: req.query })
@ -176,8 +177,7 @@ const addVideoRedundancyValidator = [
const removeVideoRedundancyValidator = [ const removeVideoRedundancyValidator = [
param('redundancyId') param('redundancyId')
.custom(isIdValid) .custom(isIdValid),
.withMessage('Should have a valid redundancy id'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking removeVideoRedundancyValidator parameters', { parameters: req.query }) logger.debug('Checking removeVideoRedundancyValidator parameters', { parameters: req.query })

View File

@ -7,11 +7,13 @@ import { logger } from '../../helpers/logger'
import { areValidationErrors } from './shared' import { areValidationErrors } from './shared'
const videosSearchValidator = [ const videosSearchValidator = [
query('search').optional().not().isEmpty().withMessage('Should have a valid search'), query('search')
.optional()
.not().isEmpty(),
query('host') query('host')
.optional() .optional()
.custom(isHostValid).withMessage('Should have a valid host'), .custom(isHostValid),
query('startDate') query('startDate')
.optional() .optional()
@ -29,18 +31,20 @@ const videosSearchValidator = [
query('durationMin') query('durationMin')
.optional() .optional()
.isInt().withMessage('Should have a valid min duration'), .isInt(),
query('durationMax') query('durationMax')
.optional() .optional()
.isInt().withMessage('Should have a valid max duration'), .isInt(),
query('uuids') query('uuids')
.optional() .optional()
.toArray() .toArray()
.customSanitizer(toCompleteUUIDs) .customSanitizer(toCompleteUUIDs)
.custom(areUUIDsValid).withMessage('Should have valid uuids'), .custom(areUUIDsValid).withMessage('Should have valid array of uuid'),
query('searchTarget').optional().custom(isSearchTargetValid).withMessage('Should have a valid search target'), query('searchTarget')
.optional()
.custom(isSearchTargetValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videos search query', { parameters: req.query }) logger.debug('Checking videos search query', { parameters: req.query })
@ -54,20 +58,20 @@ const videosSearchValidator = [
const videoChannelsListSearchValidator = [ const videoChannelsListSearchValidator = [
query('search') query('search')
.optional() .optional()
.not().isEmpty().withMessage('Should have a valid search'), .not().isEmpty(),
query('host') query('host')
.optional() .optional()
.custom(isHostValid).withMessage('Should have a valid host'), .custom(isHostValid),
query('searchTarget') query('searchTarget')
.optional() .optional()
.custom(isSearchTargetValid).withMessage('Should have a valid search target'), .custom(isSearchTargetValid),
query('handles') query('handles')
.optional() .optional()
.toArray() .toArray()
.custom(isNotEmptyStringArray).withMessage('Should have valid handles'), .custom(isNotEmptyStringArray).withMessage('Should have valid array of handles'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking video channels search query', { parameters: req.query }) logger.debug('Checking video channels search query', { parameters: req.query })
@ -81,21 +85,21 @@ const videoChannelsListSearchValidator = [
const videoPlaylistsListSearchValidator = [ const videoPlaylistsListSearchValidator = [
query('search') query('search')
.optional() .optional()
.not().isEmpty().withMessage('Should have a valid search'), .not().isEmpty(),
query('host') query('host')
.optional() .optional()
.custom(isHostValid).withMessage('Should have a valid host'), .custom(isHostValid),
query('searchTarget') query('searchTarget')
.optional() .optional()
.custom(isSearchTargetValid).withMessage('Should have a valid search target'), .custom(isSearchTargetValid),
query('uuids') query('uuids')
.optional() .optional()
.toArray() .toArray()
.customSanitizer(toCompleteUUIDs) .customSanitizer(toCompleteUUIDs)
.custom(areUUIDsValid).withMessage('Should have valid uuids'), .custom(areUUIDsValid).withMessage('Should have valid array of uuid'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking video playlists search query', { parameters: req.query }) logger.debug('Checking video playlists search query', { parameters: req.query })

View File

@ -33,11 +33,11 @@ const serverGetValidator = [
const contactAdministratorValidator = [ const contactAdministratorValidator = [
body('fromName') body('fromName')
.custom(isUserDisplayNameValid).withMessage('Should have a valid name'), .custom(isUserDisplayNameValid),
body('fromEmail') body('fromEmail')
.isEmail().withMessage('Should have a valid email'), .isEmail(),
body('body') body('body')
.custom(isValidContactBody).withMessage('Should have a valid body'), .custom(isValidContactBody),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking contactAdministratorValidator parameters', { parameters: req.body }) logger.debug('Checking contactAdministratorValidator parameters', { parameters: req.body })

View File

@ -26,13 +26,13 @@ function areValidationErrors (req: express.Request, res: express.Response) {
function isValidVideoIdParam (paramName: string) { function isValidVideoIdParam (paramName: string) {
return param(paramName) return param(paramName)
.customSanitizer(toCompleteUUID) .customSanitizer(toCompleteUUID)
.custom(isIdOrUUIDValid).withMessage('Should have a valid video id') .custom(isIdOrUUIDValid).withMessage('Should have a valid video id (id, short UUID or UUID)')
} }
function isValidPlaylistIdParam (paramName: string) { function isValidPlaylistIdParam (paramName: string) {
return param(paramName) return param(paramName)
.customSanitizer(toCompleteUUID) .customSanitizer(toCompleteUUID)
.custom(isIdOrUUIDValid).withMessage('Should have a valid playlist id') .custom(isIdOrUUIDValid).withMessage('Should have a valid playlist id (id, short UUID or UUID)')
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -10,7 +10,9 @@ function checkSortFactory (columns: string[], tags: string[] = []) {
function checkSort (sortableColumns: string[], tags: string[] = []) { function checkSort (sortableColumns: string[], tags: string[] = []) {
return [ return [
query('sort').optional().isIn(sortableColumns).withMessage('Should have correct sortable column'), query('sort')
.optional()
.isIn(sortableColumns),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking sort parameters', { parameters: req.query, tags }) logger.debug('Checking sort parameters', { parameters: req.query, tags })

View File

@ -8,9 +8,12 @@ import { PluginManager } from '../../lib/plugins/plugin-manager'
import { areValidationErrors } from './shared' import { areValidationErrors } from './shared'
const serveThemeCSSValidator = [ const serveThemeCSSValidator = [
param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'), param('themeName')
param('themeVersion').custom(isPluginVersionValid).withMessage('Should have a valid theme version'), .custom(isPluginNameValid),
param('staticEndpoint').custom(isSafePath).withMessage('Should have a valid static endpoint'), param('themeVersion')
.custom(isPluginVersionValid),
param('staticEndpoint')
.custom(isSafePath),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking serveThemeCSS parameters', { parameters: req.params }) logger.debug('Checking serveThemeCSS parameters', { parameters: req.params })

View File

@ -7,7 +7,7 @@ import { areValidationErrors } from './shared'
const userHistoryListValidator = [ const userHistoryListValidator = [
query('search') query('search')
.optional() .optional()
.custom(exists).withMessage('Should have a valid search'), .custom(exists),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking userHistoryListValidator parameters', { parameters: req.query }) logger.debug('Checking userHistoryListValidator parameters', { parameters: req.query })
@ -34,7 +34,7 @@ const userHistoryRemoveAllValidator = [
const userHistoryRemoveElementValidator = [ const userHistoryRemoveElementValidator = [
param('videoId') param('videoId')
.custom(isIdValid).withMessage('Should have a valid video id'), .custom(isIdValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking userHistoryRemoveElementValidator parameters', { parameters: req.params }) logger.debug('Checking userHistoryRemoveElementValidator parameters', { parameters: req.params })

View File

@ -22,29 +22,29 @@ const listUserNotificationsValidator = [
const updateNotificationSettingsValidator = [ const updateNotificationSettingsValidator = [
body('newVideoFromSubscription') body('newVideoFromSubscription')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid new video from subscription notification setting'), .custom(isUserNotificationSettingValid),
body('newCommentOnMyVideo') body('newCommentOnMyVideo')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid new comment on my video notification setting'), .custom(isUserNotificationSettingValid),
body('abuseAsModerator') body('abuseAsModerator')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid abuse as moderator notification setting'), .custom(isUserNotificationSettingValid),
body('videoAutoBlacklistAsModerator') body('videoAutoBlacklistAsModerator')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid video auto blacklist notification setting'), .custom(isUserNotificationSettingValid),
body('blacklistOnMyVideo') body('blacklistOnMyVideo')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid new blacklist on my video notification setting'), .custom(isUserNotificationSettingValid),
body('myVideoImportFinished') body('myVideoImportFinished')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid video import finished video notification setting'), .custom(isUserNotificationSettingValid),
body('myVideoPublished') body('myVideoPublished')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid video published notification setting'), .custom(isUserNotificationSettingValid),
body('commentMention') body('commentMention')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid comment mention notification setting'), .custom(isUserNotificationSettingValid),
body('newFollow') body('newFollow')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid new follow notification setting'), .custom(isUserNotificationSettingValid),
body('newUserRegistration') body('newUserRegistration')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid new user registration notification setting'), .custom(isUserNotificationSettingValid),
body('newInstanceFollower') body('newInstanceFollower')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid new instance follower notification setting'), .custom(isUserNotificationSettingValid),
body('autoInstanceFollowing') body('autoInstanceFollowing')
.custom(isUserNotificationSettingValid).withMessage('Should have a valid new instance following notification setting'), .custom(isUserNotificationSettingValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body }) logger.debug('Checking updateNotificationSettingsValidator parameters', { parameters: req.body })
@ -58,7 +58,7 @@ const updateNotificationSettingsValidator = [
const markAsReadUserNotificationsValidator = [ const markAsReadUserNotificationsValidator = [
body('ids') body('ids')
.optional() .optional()
.custom(isNotEmptyIntArray).withMessage('Should have a valid notification ids to mark as read'), .custom(isNotEmptyIntArray).withMessage('Should have a valid array of notification ids'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body }) logger.debug('Checking markAsReadUserNotificationsValidator parameters', { parameters: req.body })

View File

@ -9,7 +9,9 @@ import { ActorFollowModel } from '../../models/actor/actor-follow'
import { areValidationErrors } from './shared' import { areValidationErrors } from './shared'
const userSubscriptionListValidator = [ const userSubscriptionListValidator = [
query('search').optional().not().isEmpty().withMessage('Should have a valid search'), query('search')
.optional()
.not().isEmpty(),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking userSubscriptionListValidator parameters', { parameters: req.query }) logger.debug('Checking userSubscriptionListValidator parameters', { parameters: req.query })
@ -21,7 +23,8 @@ const userSubscriptionListValidator = [
] ]
const userSubscriptionAddValidator = [ const userSubscriptionAddValidator = [
body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), body('uri')
.custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking userSubscriptionAddValidator parameters', { parameters: req.body }) logger.debug('Checking userSubscriptionAddValidator parameters', { parameters: req.body })
@ -35,7 +38,7 @@ const userSubscriptionAddValidator = [
const areSubscriptionsExistValidator = [ const areSubscriptionsExistValidator = [
query('uris') query('uris')
.customSanitizer(toArray) .customSanitizer(toArray)
.custom(areValidActorHandles).withMessage('Should have a valid uri array'), .custom(areValidActorHandles).withMessage('Should have a valid array of URIs'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking areSubscriptionsExistValidator parameters', { parameters: req.query }) logger.debug('Checking areSubscriptionsExistValidator parameters', { parameters: req.query })
@ -47,7 +50,8 @@ const areSubscriptionsExistValidator = [
] ]
const userSubscriptionGetValidator = [ const userSubscriptionGetValidator = [
param('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to unfollow'), param('uri')
.custom(isValidActorHandle),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking userSubscriptionGetValidator parameters', { parameters: req.params }) logger.debug('Checking userSubscriptionGetValidator parameters', { parameters: req.params })

View File

@ -38,7 +38,7 @@ const usersListValidator = [
query('blocked') query('blocked')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.isBoolean().withMessage('Should be a valid boolean banned state'), .isBoolean().withMessage('Should be a valid blocked boolena'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersList parameters', { parameters: req.query }) logger.debug('Checking usersList parameters', { parameters: req.query })
@ -50,19 +50,30 @@ const usersListValidator = [
] ]
const usersAddValidator = [ const usersAddValidator = [
body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), body('username')
body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), .custom(isUserUsernameValid)
body('email').isEmail().withMessage('Should have a valid email'), .withMessage('Should have a valid username (lowercase alphanumeric characters)'),
body('password')
.custom(isUserPasswordValidOrEmpty),
body('email')
.isEmail(),
body('channelName').optional().custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), body('channelName')
.optional()
.custom(isVideoChannelUsernameValid),
body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), body('videoQuota')
body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), .custom(isUserVideoQuotaValid),
body('videoQuotaDaily')
.custom(isUserVideoQuotaDailyValid),
body('role') body('role')
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isUserRoleValid).withMessage('Should have a valid role'), .custom(isUserRoleValid),
body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'),
body('adminFlags')
.optional()
.custom(isUserAdminFlagsValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersAdd parameters', { parameters: omit(req.body, 'password') }) logger.debug('Checking usersAdd parameters', { parameters: omit(req.body, 'password') })
@ -97,19 +108,22 @@ const usersAddValidator = [
] ]
const usersRegisterValidator = [ const usersRegisterValidator = [
body('username').custom(isUserUsernameValid).withMessage('Should have a valid username'), body('username')
body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'), .custom(isUserUsernameValid),
body('email').isEmail().withMessage('Should have a valid email'), body('password')
.custom(isUserPasswordValid),
body('email')
.isEmail(),
body('displayName') body('displayName')
.optional() .optional()
.custom(isUserDisplayNameValid).withMessage('Should have a valid display name'), .custom(isUserDisplayNameValid),
body('channel.name') body('channel.name')
.optional() .optional()
.custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), .custom(isVideoChannelUsernameValid),
body('channel.displayName') body('channel.displayName')
.optional() .optional()
.custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), .custom(isVideoChannelDisplayNameValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') }) logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') })
@ -141,7 +155,8 @@ const usersRegisterValidator = [
] ]
const usersRemoveValidator = [ const usersRemoveValidator = [
param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), param('id')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersRemove parameters', { parameters: req.params }) logger.debug('Checking usersRemove parameters', { parameters: req.params })
@ -159,8 +174,11 @@ const usersRemoveValidator = [
] ]
const usersBlockingValidator = [ const usersBlockingValidator = [
param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), param('id')
body('reason').optional().custom(isUserBlockedReasonValid).withMessage('Should have a valid blocking reason'), .custom(isIdValid),
body('reason')
.optional()
.custom(isUserBlockedReasonValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersBlocking parameters', { parameters: req.params }) logger.debug('Checking usersBlocking parameters', { parameters: req.params })
@ -189,19 +207,33 @@ const deleteMeValidator = [
] ]
const usersUpdateValidator = [ const usersUpdateValidator = [
param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), param('id').custom(isIdValid),
body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'), body('password')
body('email').optional().isEmail().withMessage('Should have a valid email attribute'), .optional()
body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'), .custom(isUserPasswordValid),
body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), body('email')
body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), .optional()
body('pluginAuth').optional(), .isEmail(),
body('emailVerified')
.optional()
.isBoolean(),
body('videoQuota')
.optional()
.custom(isUserVideoQuotaValid),
body('videoQuotaDaily')
.optional()
.custom(isUserVideoQuotaDailyValid),
body('pluginAuth')
.optional()
.exists(),
body('role') body('role')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isUserRoleValid).withMessage('Should have a valid role'), .custom(isUserRoleValid),
body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), body('adminFlags')
.optional()
.custom(isUserAdminFlagsValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersUpdate parameters', { parameters: req.body }) logger.debug('Checking usersUpdate parameters', { parameters: req.body })
@ -221,37 +253,37 @@ const usersUpdateValidator = [
const usersUpdateMeValidator = [ const usersUpdateMeValidator = [
body('displayName') body('displayName')
.optional() .optional()
.custom(isUserDisplayNameValid).withMessage('Should have a valid display name'), .custom(isUserDisplayNameValid),
body('description') body('description')
.optional() .optional()
.custom(isUserDescriptionValid).withMessage('Should have a valid description'), .custom(isUserDescriptionValid),
body('currentPassword') body('currentPassword')
.optional() .optional()
.custom(isUserPasswordValid).withMessage('Should have a valid current password'), .custom(isUserPasswordValid),
body('password') body('password')
.optional() .optional()
.custom(isUserPasswordValid).withMessage('Should have a valid password'), .custom(isUserPasswordValid),
body('email') body('email')
.optional() .optional()
.isEmail().withMessage('Should have a valid email attribute'), .isEmail(),
body('nsfwPolicy') body('nsfwPolicy')
.optional() .optional()
.custom(isUserNSFWPolicyValid).withMessage('Should have a valid display Not Safe For Work policy'), .custom(isUserNSFWPolicyValid),
body('autoPlayVideo') body('autoPlayVideo')
.optional() .optional()
.custom(isUserAutoPlayVideoValid).withMessage('Should have a valid automatically plays video attribute'), .custom(isUserAutoPlayVideoValid),
body('p2pEnabled') body('p2pEnabled')
.optional() .optional()
.custom(isUserP2PEnabledValid).withMessage('Should have a valid p2p enabled boolean'), .custom(isUserP2PEnabledValid).withMessage('Should have a valid p2p enabled boolean'),
body('videoLanguages') body('videoLanguages')
.optional() .optional()
.custom(isUserVideoLanguages).withMessage('Should have a valid video languages attribute'), .custom(isUserVideoLanguages),
body('videosHistoryEnabled') body('videosHistoryEnabled')
.optional() .optional()
.custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled boolean'),
body('theme') body('theme')
.optional() .optional()
.custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), .custom(v => isThemeNameValid(v) && isThemeRegistered(v)),
body('noInstanceConfigWarningModal') body('noInstanceConfigWarningModal')
.optional() .optional()
@ -296,8 +328,11 @@ const usersUpdateMeValidator = [
] ]
const usersGetValidator = [ const usersGetValidator = [
param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), param('id')
query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), .custom(isIdValid),
query('withStats')
.optional()
.isBoolean().withMessage('Should have a valid withStats boolean'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersGet parameters', { parameters: req.params }) logger.debug('Checking usersGet parameters', { parameters: req.params })
@ -326,12 +361,12 @@ const usersVideosValidator = [
query('isLive') query('isLive')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid live boolean'), .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'),
query('channelId') query('channelId')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isIdValid).withMessage('Should have a valid channel id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersVideosValidator parameters', { parameters: req.query }) logger.debug('Checking usersVideosValidator parameters', { parameters: req.query })
@ -384,7 +419,8 @@ const ensureUserRegistrationAllowedForIP = [
] ]
const usersAskResetPasswordValidator = [ const usersAskResetPasswordValidator = [
body('email').isEmail().not().isEmpty().withMessage('Should have a valid email'), body('email')
.isEmail(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersAskResetPassword parameters', { parameters: req.body }) logger.debug('Checking usersAskResetPassword parameters', { parameters: req.body })
@ -403,9 +439,12 @@ const usersAskResetPasswordValidator = [
] ]
const usersResetPasswordValidator = [ const usersResetPasswordValidator = [
param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), param('id')
body('verificationString').not().isEmpty().withMessage('Should have a valid verification string'), .custom(isIdValid),
body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'), body('verificationString')
.not().isEmpty(),
body('password')
.custom(isUserPasswordValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersResetPassword parameters', { parameters: req.params }) logger.debug('Checking usersResetPassword parameters', { parameters: req.params })

View File

@ -29,7 +29,7 @@ const videosBlacklistAddValidator = [
.custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
body('reason') body('reason')
.optional() .optional()
.custom(isVideoBlacklistReasonValid).withMessage('Should have a valid reason'), .custom(isVideoBlacklistReasonValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params }) logger.debug('Checking videosBlacklistAdd parameters', { parameters: req.params })

View File

@ -18,7 +18,7 @@ const addVideoCaptionValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
param('captionLanguage') param('captionLanguage')
.custom(isVideoCaptionLanguageValid).not().isEmpty().withMessage('Should have a valid caption language'), .custom(isVideoCaptionLanguageValid).not().isEmpty(),
body('captionfile') body('captionfile')
.custom((_, { req }) => isVideoCaptionFile(req.files, 'captionfile')) .custom((_, { req }) => isVideoCaptionFile(req.files, 'captionfile'))

View File

@ -20,8 +20,11 @@ export const ensureSyncIsEnabled = (req: express.Request, res: express.Response,
} }
export const videoChannelSyncValidator = [ export const videoChannelSyncValidator = [
body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), body('externalChannelUrl')
body('videoChannelId').isInt().withMessage('Should have a valid video channel id'), .custom(isUrlValid),
body('videoChannelId')
.isInt(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoChannelSync parameters', { parameters: req.body }) logger.debug('Checking videoChannelSync parameters', { parameters: req.body })

View File

@ -19,10 +19,16 @@ import { areValidationErrors, checkUserQuota, doesVideoChannelNameWithHostExist
import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs' import { doesVideoChannelSyncIdExist } from '../shared/video-channel-syncs'
export const videoChannelsAddValidator = [ export const videoChannelsAddValidator = [
body('name').custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), body('name')
body('displayName').custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), .custom(isVideoChannelUsernameValid),
body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), body('displayName')
body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), .custom(isVideoChannelDisplayNameValid),
body('description')
.optional()
.custom(isVideoChannelDescriptionValid),
body('support')
.optional()
.custom(isVideoChannelSupportValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body }) logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body })
@ -49,16 +55,18 @@ export const videoChannelsAddValidator = [
] ]
export const videoChannelsUpdateValidator = [ export const videoChannelsUpdateValidator = [
param('nameWithHost').exists().withMessage('Should have an video channel name with host'), param('nameWithHost')
.exists(),
body('displayName') body('displayName')
.optional() .optional()
.custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), .custom(isVideoChannelDisplayNameValid),
body('description') body('description')
.optional() .optional()
.custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'), .custom(isVideoChannelDescriptionValid),
body('support') body('support')
.optional() .optional()
.custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'), .custom(isVideoChannelSupportValid),
body('bulkVideosSupportUpdate') body('bulkVideosSupportUpdate')
.optional() .optional()
.custom(isBooleanValid).withMessage('Should have a valid bulkVideosSupportUpdate boolean field'), .custom(isBooleanValid).withMessage('Should have a valid bulkVideosSupportUpdate boolean field'),
@ -83,7 +91,8 @@ export const videoChannelsRemoveValidator = [
] ]
export const videoChannelsNameWithHostValidator = [ export const videoChannelsNameWithHostValidator = [
param('nameWithHost').exists().withMessage('Should have an video channel name with host'), param('nameWithHost')
.exists(),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params }) logger.debug('Checking videoChannelsNameWithHostValidator parameters', { parameters: req.params })
@ -124,7 +133,7 @@ export const videoChannelStatsValidator = [
query('withStats') query('withStats')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid stats flag'), .custom(isBooleanValid).withMessage('Should have a valid stats flag boolean'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return if (areValidationErrors(req, res)) return
@ -133,7 +142,9 @@ export const videoChannelStatsValidator = [
] ]
export const videoChannelsListValidator = [ export const videoChannelsListValidator = [
query('search').optional().not().isEmpty().withMessage('Should have a valid search'), query('search')
.optional()
.not().isEmpty(),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking video channels search query', { parameters: req.query }) logger.debug('Checking video channels search query', { parameters: req.query })
@ -145,11 +156,12 @@ export const videoChannelsListValidator = [
] ]
export const videoChannelImportVideosValidator = [ export const videoChannelImportVideosValidator = [
body('externalChannelUrl').custom(isUrlValid).withMessage('Should have a valid channel url'), body('externalChannelUrl')
.custom(isUrlValid),
body('videoChannelSyncId') body('videoChannelSyncId')
.optional() .optional()
.custom(isIdValid).withMessage('Should have a valid channel sync id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoChannelImport parameters', { parameters: req.body }) logger.debug('Checking videoChannelImport parameters', { parameters: req.body })

View File

@ -19,28 +19,28 @@ import {
const listVideoCommentsValidator = [ const listVideoCommentsValidator = [
query('isLocal') query('isLocal')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid) .custom(isBooleanValid)
.withMessage('Should have a valid is local boolean'), .withMessage('Should have a valid isLocal boolean'),
query('onLocalVideo') query('onLocalVideo')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid) .custom(isBooleanValid)
.withMessage('Should have a valid is on local video boolean'), .withMessage('Should have a valid onLocalVideo boolean'),
query('search') query('search')
.optional() .optional()
.custom(exists).withMessage('Should have a valid search'), .custom(exists),
query('searchAccount') query('searchAccount')
.optional() .optional()
.custom(exists).withMessage('Should have a valid account search'), .custom(exists),
query('searchVideo') query('searchVideo')
.optional() .optional()
.custom(exists).withMessage('Should have a valid video search'), .custom(exists),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query }) logger.debug('Checking listVideoCommentsValidator parameters.', { parameters: req.query })
@ -70,7 +70,7 @@ const listVideoThreadCommentsValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
param('threadId') param('threadId')
.custom(isIdValid).not().isEmpty().withMessage('Should have a valid threadId'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params }) logger.debug('Checking listVideoThreadComments parameters.', { parameters: req.params })
@ -89,7 +89,7 @@ const addVideoCommentThreadValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
body('text') body('text')
.custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), .custom(isValidVideoCommentText),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body }) logger.debug('Checking addVideoCommentThread parameters.', { parameters: req.params, body: req.body })
@ -109,9 +109,9 @@ const addVideoCommentThreadValidator = [
const addVideoCommentReplyValidator = [ const addVideoCommentReplyValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), param('commentId').custom(isIdValid),
body('text').custom(isValidVideoCommentText).not().isEmpty().withMessage('Should have a valid comment text'), body('text').custom(isValidVideoCommentText),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body }) logger.debug('Checking addVideoCommentReply parameters.', { parameters: req.params, body: req.body })
@ -133,7 +133,7 @@ const videoCommentGetValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
param('commentId') param('commentId')
.custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params })
@ -149,7 +149,8 @@ const videoCommentGetValidator = [
const removeVideoCommentValidator = [ const removeVideoCommentValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'), param('commentId')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking removeVideoCommentValidator parameters.', { parameters: req.params }) logger.debug('Checking removeVideoCommentValidator parameters.', { parameters: req.params })

View File

@ -41,7 +41,7 @@ const videoFilesDeleteWebTorrentFileValidator = [
isValidVideoIdParam('id'), isValidVideoIdParam('id'),
param('videoFileId') param('videoFileId')
.custom(isIdValid).withMessage('Should have a valid file id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoFilesDeleteWebTorrentFile parameters', { parameters: req.params }) logger.debug('Checking videoFilesDeleteWebTorrentFile parameters', { parameters: req.params })
@ -109,7 +109,7 @@ const videoFilesDeleteHLSFileValidator = [
isValidVideoIdParam('id'), isValidVideoIdParam('id'),
param('videoFileId') param('videoFileId')
.custom(isIdValid).withMessage('Should have a valid file id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoFilesDeleteHLSFile parameters', { parameters: req.params }) logger.debug('Checking videoFilesDeleteHLSFile parameters', { parameters: req.params })

View File

@ -19,13 +19,13 @@ import { getCommonVideoEditAttributes } from './videos'
const videoImportAddValidator = getCommonVideoEditAttributes().concat([ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
body('channelId') body('channelId')
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isIdValid).withMessage('Should have correct video channel id'), .custom(isIdValid),
body('targetUrl') body('targetUrl')
.optional() .optional()
.custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), .custom(isVideoImportTargetUrlValid),
body('magnetUri') body('magnetUri')
.optional() .optional()
.custom(isVideoMagnetUriValid).withMessage('Should have a valid video magnet URI'), .custom(isVideoMagnetUriValid),
body('torrentfile') body('torrentfile')
.custom((value, { req }) => isVideoImportTorrentFile(req.files)) .custom((value, { req }) => isVideoImportTorrentFile(req.files))
.withMessage( .withMessage(
@ -95,7 +95,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
const getMyVideoImportsValidator = [ const getMyVideoImportsValidator = [
query('videoChannelSyncId') query('videoChannelSyncId')
.optional() .optional()
.custom(isIdValid).withMessage('Should have correct videoChannelSync id'), .custom(isIdValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking getMyVideoImportsValidator parameters', { parameters: req.params }) logger.debug('Checking getMyVideoImportsValidator parameters', { parameters: req.params })
@ -108,7 +108,7 @@ const getMyVideoImportsValidator = [
const videoImportDeleteValidator = [ const videoImportDeleteValidator = [
param('id') param('id')
.custom(isIdValid).withMessage('Should have correct import id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.params }) logger.debug('Checking videoImportDeleteValidator parameters', { parameters: req.params })
@ -131,7 +131,7 @@ const videoImportDeleteValidator = [
const videoImportCancelValidator = [ const videoImportCancelValidator = [
param('id') param('id')
.custom(isIdValid).withMessage('Should have correct import id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoImportCancelValidator parameters', { parameters: req.params }) logger.debug('Checking videoImportCancelValidator parameters', { parameters: req.params })

View File

@ -56,7 +56,7 @@ const videoLiveGetValidator = [
const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
body('channelId') body('channelId')
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isIdValid).withMessage('Should have correct video channel id'), .custom(isIdValid),
body('name') body('name')
.custom(isVideoNameValid).withMessage( .custom(isVideoNameValid).withMessage(
@ -66,18 +66,17 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
body('saveReplay') body('saveReplay')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'), .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'),
body('permanentLive') body('permanentLive')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid permanentLive attribute'), .custom(isBooleanValid).withMessage('Should have a valid permanentLive boolean'),
body('latencyMode') body('latencyMode')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isLiveLatencyModeValid) .custom(isLiveLatencyModeValid),
.withMessage('Should have a valid latency mode attribute'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoLiveAddValidator parameters', { parameters: req.body }) logger.debug('Checking videoLiveAddValidator parameters', { parameters: req.body })
@ -156,13 +155,12 @@ const videoLiveUpdateValidator = [
body('saveReplay') body('saveReplay')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid saveReplay attribute'), .custom(isBooleanValid).withMessage('Should have a valid saveReplay boolean'),
body('latencyMode') body('latencyMode')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isLiveLatencyModeValid) .custom(isLiveLatencyModeValid),
.withMessage('Should have a valid latency mode attribute'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoLiveUpdateValidator parameters', { parameters: req.body }) logger.debug('Checking videoLiveUpdateValidator parameters', { parameters: req.body })

View File

@ -41,7 +41,7 @@ const videosChangeOwnershipValidator = [
const videosTerminateChangeOwnershipValidator = [ const videosTerminateChangeOwnershipValidator = [
param('id') param('id')
.custom(isIdValid).withMessage('Should have a valid id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking changeOwnership parameters', { parameters: req.params }) logger.debug('Checking changeOwnership parameters', { parameters: req.params })

View File

@ -45,7 +45,7 @@ import {
const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([
body('displayName') body('displayName')
.custom(isVideoPlaylistNameValid).withMessage('Should have a valid display name'), .custom(isVideoPlaylistNameValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylistsAddValidator parameters', { parameters: req.body }) logger.debug('Checking videoPlaylistsAddValidator parameters', { parameters: req.body })
@ -73,7 +73,7 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([
body('displayName') body('displayName')
.optional() .optional()
.custom(isVideoPlaylistNameValid).withMessage('Should have a valid display name'), .custom(isVideoPlaylistNameValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylistsUpdateValidator parameters', { parameters: req.body }) logger.debug('Checking videoPlaylistsUpdateValidator parameters', { parameters: req.body })
@ -184,7 +184,9 @@ const videoPlaylistsGetValidator = (fetchType: VideoPlaylistFetchType) => {
} }
const videoPlaylistsSearchValidator = [ const videoPlaylistsSearchValidator = [
query('search').optional().not().isEmpty().withMessage('Should have a valid search'), query('search')
.optional()
.not().isEmpty(),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylists search query', { parameters: req.query }) logger.debug('Checking videoPlaylists search query', { parameters: req.query })
@ -200,13 +202,13 @@ const videoPlaylistsAddVideoValidator = [
body('videoId') body('videoId')
.customSanitizer(toCompleteUUID) .customSanitizer(toCompleteUUID)
.custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), .custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid/short uuid'),
body('startTimestamp') body('startTimestamp')
.optional() .optional()
.custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'), .custom(isVideoPlaylistTimestampValid),
body('stopTimestamp') body('stopTimestamp')
.optional() .optional()
.custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'), .custom(isVideoPlaylistTimestampValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylistsAddVideoValidator parameters', { parameters: req.params }) logger.debug('Checking videoPlaylistsAddVideoValidator parameters', { parameters: req.params })
@ -230,13 +232,13 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [
isValidPlaylistIdParam('playlistId'), isValidPlaylistIdParam('playlistId'),
param('playlistElementId') param('playlistElementId')
.customSanitizer(toCompleteUUID) .customSanitizer(toCompleteUUID)
.custom(isIdValid).withMessage('Should have an element id/uuid'), .custom(isIdValid).withMessage('Should have an element id/uuid/short uuid'),
body('startTimestamp') body('startTimestamp')
.optional() .optional()
.custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid start timestamp'), .custom(isVideoPlaylistTimestampValid),
body('stopTimestamp') body('stopTimestamp')
.optional() .optional()
.custom(isVideoPlaylistTimestampValid).withMessage('Should have a valid stop timestamp'), .custom(isVideoPlaylistTimestampValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylistsRemoveVideoValidator parameters', { parameters: req.params }) logger.debug('Checking videoPlaylistsRemoveVideoValidator parameters', { parameters: req.params })
@ -266,7 +268,7 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [
const videoPlaylistElementAPGetValidator = [ const videoPlaylistElementAPGetValidator = [
isValidPlaylistIdParam('playlistId'), isValidPlaylistIdParam('playlistId'),
param('playlistElementId') param('playlistElementId')
.custom(isIdValid).withMessage('Should have an playlist element id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylistElementAPGetValidator parameters', { parameters: req.params }) logger.debug('Checking videoPlaylistElementAPGetValidator parameters', { parameters: req.params })
@ -300,13 +302,14 @@ const videoPlaylistElementAPGetValidator = [
const videoPlaylistsReorderVideosValidator = [ const videoPlaylistsReorderVideosValidator = [
isValidPlaylistIdParam('playlistId'), isValidPlaylistIdParam('playlistId'),
body('startPosition') body('startPosition')
.isInt({ min: 1 }).withMessage('Should have a valid start position'), .isInt({ min: 1 }),
body('insertAfterPosition') body('insertAfterPosition')
.isInt({ min: 0 }).withMessage('Should have a valid insert after position'), .isInt({ min: 0 }),
body('reorderLength') body('reorderLength')
.optional() .optional()
.isInt({ min: 1 }).withMessage('Should have a valid range length'), .isInt({ min: 1 }),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoPlaylistsReorderVideosValidator parameters', { parameters: req.params }) logger.debug('Checking videoPlaylistsReorderVideosValidator parameters', { parameters: req.params })
@ -340,7 +343,7 @@ const videoPlaylistsReorderVideosValidator = [
const commonVideoPlaylistFiltersValidator = [ const commonVideoPlaylistFiltersValidator = [
query('playlistType') query('playlistType')
.optional() .optional()
.custom(isVideoPlaylistTypeValid).withMessage('Should have a valid playlist type'), .custom(isVideoPlaylistTypeValid),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking commonVideoPlaylistFiltersValidator parameters', { parameters: req.params }) logger.debug('Checking commonVideoPlaylistFiltersValidator parameters', { parameters: req.params })
@ -399,11 +402,11 @@ function getCommonPlaylistEditAttributes () {
body('description') body('description')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toValueOrNull)
.custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), .custom(isVideoPlaylistDescriptionValid),
body('privacy') body('privacy')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), .custom(isVideoPlaylistPrivacyValid),
body('videoChannelId') body('videoChannelId')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)

View File

@ -13,7 +13,8 @@ import { areValidationErrors, checkCanSeeVideo, doesVideoExist, isValidVideoIdPa
const videoUpdateRateValidator = [ const videoUpdateRateValidator = [
isValidVideoIdParam('id'), isValidVideoIdParam('id'),
body('rating').custom(isVideoRatingTypeValid).withMessage('Should have a valid rate type'), body('rating')
.custom(isVideoRatingTypeValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoRate parameters', { parameters: req.body }) logger.debug('Checking videoRate parameters', { parameters: req.body })
@ -29,8 +30,10 @@ const videoUpdateRateValidator = [
const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) { const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
return [ return [
param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), param('name')
param('videoId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid videoId'), .custom(isAccountNameValid),
param('videoId')
.custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params }) logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params })
@ -53,7 +56,9 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
} }
const videoRatingValidator = [ const videoRatingValidator = [
query('rating').optional().custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'), query('rating')
.optional()
.custom(isRatingValid).withMessage('Value must be one of "like" or "dislike"'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking rating parameter', { parameters: req.params }) logger.debug('Checking rating parameter', { parameters: req.params })

View File

@ -10,7 +10,7 @@ const videosShareValidator = [
isValidVideoIdParam('id'), isValidVideoIdParam('id'),
param('actorId') param('actorId')
.custom(isIdValid).not().isEmpty().withMessage('Should have a valid actor id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoShare parameters', { parameters: req.params }) logger.debug('Checking videoShare parameters', { parameters: req.params })

View File

@ -12,13 +12,11 @@ const videoOverallStatsValidator = [
query('startDate') query('startDate')
.optional() .optional()
.custom(isDateValid) .custom(isDateValid),
.withMessage('Should have a valid start date'),
query('endDate') query('endDate')
.optional() .optional()
.custom(isDateValid) .custom(isDateValid),
.withMessage('Should have a valid end date'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoOverallStatsValidator parameters', { parameters: req.body }) logger.debug('Checking videoOverallStatsValidator parameters', { parameters: req.body })
@ -54,18 +52,15 @@ const videoTimeserieStatsValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
param('metric') param('metric')
.custom(isValidStatTimeserieMetric) .custom(isValidStatTimeserieMetric),
.withMessage('Should have a valid timeserie metric'),
query('startDate') query('startDate')
.optional() .optional()
.custom(isDateValid) .custom(isDateValid),
.withMessage('Should have a valid start date'),
query('endDate') query('endDate')
.optional() .optional()
.custom(isDateValid) .custom(isDateValid),
.withMessage('Should have a valid end date'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoTimeserieStatsValidator parameters', { parameters: req.body }) logger.debug('Checking videoTimeserieStatsValidator parameters', { parameters: req.body })

View File

@ -16,9 +16,11 @@ import { logger } from '../../../helpers/logger'
import { areValidationErrors, checkUserCanManageVideo, checkUserQuota, doesVideoExist } from '../shared' import { areValidationErrors, checkUserCanManageVideo, checkUserQuota, doesVideoExist } from '../shared'
const videoStudioAddEditionValidator = [ const videoStudioAddEditionValidator = [
param('videoId').custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid'), param('videoId')
.custom(isIdOrUUIDValid).withMessage('Should have a valid video id/uuid/short uuid'),
body('tasks').custom(isValidStudioTasksArray).withMessage('Should have a valid array of tasks'), body('tasks')
.custom(isValidStudioTasksArray).withMessage('Should have a valid array of tasks'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoStudioAddEditionValidator parameters.', { parameters: req.params, body: req.body, files: req.files }) logger.debug('Checking videoStudioAddEditionValidator parameters.', { parameters: req.params, body: req.body, files: req.files })

View File

@ -11,7 +11,7 @@ const createTranscodingValidator = [
isValidVideoIdParam('videoId'), isValidVideoIdParam('videoId'),
body('transcodingType') body('transcodingType')
.custom(isValidCreateTranscodingType).withMessage('Should have a valid transcoding type'), .custom(isValidCreateTranscodingType),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking createTranscodingValidator parameters', { parameters: req.body }) logger.debug('Checking createTranscodingValidator parameters', { parameters: req.body })

View File

@ -10,7 +10,7 @@ import { getCachedVideoDuration } from '@server/lib/video'
const getVideoLocalViewerValidator = [ const getVideoLocalViewerValidator = [
param('localViewerId') param('localViewerId')
.custom(isIdValid).withMessage('Should have a valid local viewer id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking getVideoLocalViewerValidator parameters', { parameters: req.params }) logger.debug('Checking getVideoLocalViewerValidator parameters', { parameters: req.params })
@ -37,7 +37,7 @@ const videoViewValidator = [
body('currentTime') body('currentTime')
.optional() // TODO: remove optional in a few versions, introduced in 4.2 .optional() // TODO: remove optional in a few versions, introduced in 4.2
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isIntOrNull).withMessage('Should have correct current time'), .custom(isIntOrNull),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoView parameters', { parameters: req.body }) logger.debug('Checking videoView parameters', { parameters: req.body })

View File

@ -69,7 +69,7 @@ const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([
), ),
body('channelId') body('channelId')
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isIdValid).withMessage('Should have correct video channel id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
@ -167,9 +167,7 @@ const videosAddResumableValidator = [
*/ */
const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([
body('filename') body('filename')
.isString() .exists(),
.exists()
.withMessage('Should have a valid filename'),
body('name') body('name')
.trim() .trim()
.custom(isVideoNameValid).withMessage( .custom(isVideoNameValid).withMessage(
@ -177,7 +175,7 @@ const videosAddResumableInitValidator = getCommonVideoEditAttributes().concat([
), ),
body('channelId') body('channelId')
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isIdValid).withMessage('Should have correct video channel id'), .custom(isIdValid),
header('x-upload-content-length') header('x-upload-content-length')
.isNumeric() .isNumeric()
@ -230,7 +228,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([
body('channelId') body('channelId')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isIdValid).withMessage('Should have correct video channel id'), .custom(isIdValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videosUpdate parameters', { parameters: req.body }) logger.debug('Checking videosUpdate parameters', { parameters: req.body })
@ -341,8 +339,7 @@ const videosRemoveValidator = [
const videosOverviewValidator = [ const videosOverviewValidator = [
query('page') query('page')
.optional() .optional()
.isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }) .isInt({ min: 1, max: OVERVIEWS.VIDEOS.SAMPLES_COUNT }),
.withMessage('Should have a valid pagination'),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return if (areValidationErrors(req, res)) return
@ -367,35 +364,35 @@ function getCommonVideoEditAttributes () {
body('category') body('category')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isVideoCategoryValid).withMessage('Should have a valid category'), .custom(isVideoCategoryValid),
body('licence') body('licence')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isVideoLicenceValid).withMessage('Should have a valid licence'), .custom(isVideoLicenceValid),
body('language') body('language')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toValueOrNull)
.custom(isVideoLanguageValid).withMessage('Should have a valid language'), .custom(isVideoLanguageValid),
body('nsfw') body('nsfw')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), .custom(isBooleanValid).withMessage('Should have a valid nsfw boolean'),
body('waitTranscoding') body('waitTranscoding')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), .custom(isBooleanValid).withMessage('Should have a valid waitTranscoding boolean'),
body('privacy') body('privacy')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toValueOrNull)
.custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), .custom(isVideoPrivacyValid),
body('description') body('description')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toValueOrNull)
.custom(isVideoDescriptionValid).withMessage('Should have a valid description'), .custom(isVideoDescriptionValid),
body('support') body('support')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toValueOrNull)
.custom(isVideoSupportValid).withMessage('Should have a valid support text'), .custom(isVideoSupportValid),
body('tags') body('tags')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toValueOrNull)
@ -407,15 +404,15 @@ function getCommonVideoEditAttributes () {
body('commentsEnabled') body('commentsEnabled')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have comments enabled boolean'), .custom(isBooleanValid).withMessage('Should have commentsEnabled boolean'),
body('downloadEnabled') body('downloadEnabled')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), .custom(isBooleanValid).withMessage('Should have downloadEnabled boolean'),
body('originallyPublishedAt') body('originallyPublishedAt')
.optional() .optional()
.customSanitizer(toValueOrNull) .customSanitizer(toValueOrNull)
.custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), .custom(isVideoOriginallyPublishedAtValid),
body('scheduleUpdate') body('scheduleUpdate')
.optional() .optional()
.customSanitizer(toValueOrNull), .customSanitizer(toValueOrNull),
@ -425,7 +422,7 @@ function getCommonVideoEditAttributes () {
body('scheduleUpdate.privacy') body('scheduleUpdate.privacy')
.optional() .optional()
.customSanitizer(toIntOrNull) .customSanitizer(toIntOrNull)
.custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') .custom(isScheduleVideoUpdatePrivacyValid)
] as (ValidationChain | ExpressPromiseHandler)[] ] as (ValidationChain | ExpressPromiseHandler)[]
} }
@ -433,59 +430,59 @@ const commonVideosFiltersValidator = [
query('categoryOneOf') query('categoryOneOf')
.optional() .optional()
.customSanitizer(toArray) .customSanitizer(toArray)
.custom(isNumberArray).withMessage('Should have a valid one of category array'), .custom(isNumberArray).withMessage('Should have a valid categoryOneOf array'),
query('licenceOneOf') query('licenceOneOf')
.optional() .optional()
.customSanitizer(toArray) .customSanitizer(toArray)
.custom(isNumberArray).withMessage('Should have a valid one of licence array'), .custom(isNumberArray).withMessage('Should have a valid licenceOneOf array'),
query('languageOneOf') query('languageOneOf')
.optional() .optional()
.customSanitizer(toArray) .customSanitizer(toArray)
.custom(isStringArray).withMessage('Should have a valid one of language array'), .custom(isStringArray).withMessage('Should have a valid languageOneOf array'),
query('privacyOneOf') query('privacyOneOf')
.optional() .optional()
.customSanitizer(toArray) .customSanitizer(toArray)
.custom(isNumberArray).withMessage('Should have a valid one of privacy array'), .custom(isNumberArray).withMessage('Should have a valid privacyOneOf array'),
query('tagsOneOf') query('tagsOneOf')
.optional() .optional()
.customSanitizer(toArray) .customSanitizer(toArray)
.custom(isStringArray).withMessage('Should have a valid one of tags array'), .custom(isStringArray).withMessage('Should have a valid tagsOneOf array'),
query('tagsAllOf') query('tagsAllOf')
.optional() .optional()
.customSanitizer(toArray) .customSanitizer(toArray)
.custom(isStringArray).withMessage('Should have a valid all of tags array'), .custom(isStringArray).withMessage('Should have a valid tagsAllOf array'),
query('nsfw') query('nsfw')
.optional() .optional()
.custom(isBooleanBothQueryValid).withMessage('Should have a valid NSFW attribute'), .custom(isBooleanBothQueryValid),
query('isLive') query('isLive')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid live boolean'), .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'),
query('filter') query('filter')
.optional() .optional()
.custom(isVideoFilterValid).withMessage('Should have a valid filter attribute'), .custom(isVideoFilterValid),
query('include') query('include')
.optional() .optional()
.custom(isVideoIncludeValid).withMessage('Should have a valid include attribute'), .custom(isVideoIncludeValid),
query('isLocal') query('isLocal')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid local boolean'), .custom(isBooleanValid).withMessage('Should have a valid isLocal boolean'),
query('hasHLSFiles') query('hasHLSFiles')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid has hls boolean'), .custom(isBooleanValid).withMessage('Should have a valid hasHLSFiles boolean'),
query('hasWebtorrentFiles') query('hasWebtorrentFiles')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid has webtorrent boolean'), .custom(isBooleanValid).withMessage('Should have a valid hasWebtorrentFiles boolean'),
query('skipCount') query('skipCount')
.optional() .optional()
.customSanitizer(toBooleanOrNull) .customSanitizer(toBooleanOrNull)
.custom(isBooleanValid).withMessage('Should have a valid skip count boolean'), .custom(isBooleanValid).withMessage('Should have a valid skipCount boolean'),
query('search') query('search')
.optional() .optional()
.custom(exists).withMessage('Should have a valid search'), .custom(exists),
(req: express.Request, res: express.Response, next: express.NextFunction) => { (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking commons video filters query', { parameters: req.query }) logger.debug('Checking commons video filters query', { parameters: req.query })

View File

@ -8,7 +8,8 @@ import { ActorModel } from '../../models/actor/actor'
import { areValidationErrors } from './shared' import { areValidationErrors } from './shared'
const webfingerValidator = [ const webfingerValidator = [
query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'), query('resource')
.custom(isWebfingerLocalResourceValid),
async (req: express.Request, res: express.Response, next: express.NextFunction) => { async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking webfinger parameters', { parameters: req.query }) logger.debug('Checking webfinger parameters', { parameters: req.query })