]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/custom-validators/video-channels.ts
Add create-import-video-file-job command
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / video-channels.ts
CommitLineData
72c7248b
C
1import * as express from 'express'
2import 'express-validator'
3import 'multer'
4e50b6a1 4import * as validator from 'validator'
3fd3ab2d
C
5import { CONSTRAINTS_FIELDS } from '../../initializers'
6import { VideoChannelModel } from '../../models/video/video-channel'
4e50b6a1 7import { exists } from './misc'
72c7248b
C
8
9const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
10
11function isVideoChannelDescriptionValid (value: string) {
12 return value === null || validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.DESCRIPTION)
13}
14
15function isVideoChannelNameValid (value: string) {
16 return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME)
17}
18
2422c46b
C
19function isVideoChannelSupportValid (value: string) {
20 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
21}
22
a2431b7d 23async function isVideoChannelExist (id: string, res: express.Response) {
3fd3ab2d 24 let videoChannel: VideoChannelModel
4e50b6a1 25 if (validator.isInt(id)) {
3fd3ab2d 26 videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id)
4e50b6a1 27 } else { // UUID
3fd3ab2d 28 videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id)
4e50b6a1
C
29 }
30
31 if (!videoChannel) {
32 res.status(404)
33 .json({ error: 'Video channel not found' })
34 .end()
35
36 return false
37 }
38
39 res.locals.videoChannel = videoChannel
40 return true
41}
42
72c7248b
C
43// ---------------------------------------------------------------------------
44
45export {
46 isVideoChannelDescriptionValid,
4e50b6a1 47 isVideoChannelNameValid,
2422c46b 48 isVideoChannelSupportValid,
a2431b7d 49 isVideoChannelExist
72c7248b 50}