1
0
Fork 0
peertube/server/helpers/custom-validators/video-channels.ts

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-10-24 17:41:09 +00:00
import * as express from 'express'
import 'express-validator'
import 'multer'
import * as validator from 'validator'
import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
2017-12-12 16:53:50 +00:00
import { VideoChannelModel } from '../../models/video/video-channel'
import { exists } from './misc'
2017-10-24 17:41:09 +00:00
const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
function isVideoChannelDescriptionValid (value: string) {
return value === null || validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.DESCRIPTION)
}
function isVideoChannelNameValid (value: string) {
return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME)
}
function isVideoChannelSupportValid (value: string) {
return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
}
2017-10-24 17:41:09 +00:00
// ---------------------------------------------------------------------------
export {
isVideoChannelDescriptionValid,
isVideoChannelNameValid,
isVideoChannelSupportValid,
2017-10-24 17:41:09 +00:00
}
function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {
if (!videoChannel) {
res.status(404)
.json({ error: 'Video channel not found' })
.end()
return false
}
res.locals.videoChannel = videoChannel
return true
}