aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/video-channels.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-16 15:25:20 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commit06a05d5f4784a7cbb27aa1188385b5679845dad8 (patch)
treeac197f3ed0768529456225ad76c912f22bc55e29 /server/helpers/custom-validators/video-channels.ts
parent4bda2e47bbc937c401ddcf14c1be53c70481a294 (diff)
downloadPeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.gz
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.tar.zst
PeerTube-06a05d5f4784a7cbb27aa1188385b5679845dad8.zip
Add subscriptions endpoints to REST API
Diffstat (limited to 'server/helpers/custom-validators/video-channels.ts')
-rw-r--r--server/helpers/custom-validators/video-channels.ts32
1 files changed, 22 insertions, 10 deletions
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts
index 2a6f56840..32faf36f7 100644
--- a/server/helpers/custom-validators/video-channels.ts
+++ b/server/helpers/custom-validators/video-channels.ts
@@ -5,6 +5,7 @@ import * as validator from 'validator'
5import { CONSTRAINTS_FIELDS } from '../../initializers' 5import { CONSTRAINTS_FIELDS } from '../../initializers'
6import { VideoChannelModel } from '../../models/video/video-channel' 6import { VideoChannelModel } from '../../models/video/video-channel'
7import { exists } from './misc' 7import { exists } from './misc'
8import { Response } from 'express'
8 9
9const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS 10const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
10 11
@@ -20,6 +21,12 @@ function isVideoChannelSupportValid (value: string) {
20 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT)) 21 return value === null || (exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.SUPPORT))
21} 22}
22 23
24async function isLocalVideoChannelNameExist (name: string, res: Response) {
25 const videoChannel = await VideoChannelModel.loadLocalByName(name)
26
27 return processVideoChannelExist(videoChannel, res)
28}
29
23async function isVideoChannelExist (id: string, res: express.Response) { 30async function isVideoChannelExist (id: string, res: express.Response) {
24 let videoChannel: VideoChannelModel 31 let videoChannel: VideoChannelModel
25 if (validator.isInt(id)) { 32 if (validator.isInt(id)) {
@@ -28,23 +35,28 @@ async function isVideoChannelExist (id: string, res: express.Response) {
28 videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id) 35 videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id)
29 } 36 }
30 37
31 if (!videoChannel) { 38 return processVideoChannelExist(videoChannel, res)
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} 39}
42 40
43// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
44 42
45export { 43export {
44 isLocalVideoChannelNameExist,
46 isVideoChannelDescriptionValid, 45 isVideoChannelDescriptionValid,
47 isVideoChannelNameValid, 46 isVideoChannelNameValid,
48 isVideoChannelSupportValid, 47 isVideoChannelSupportValid,
49 isVideoChannelExist 48 isVideoChannelExist
50} 49}
50
51function processVideoChannelExist (videoChannel: VideoChannelModel, res: express.Response) {
52 if (!videoChannel) {
53 res.status(404)
54 .json({ error: 'Video channel not found' })
55 .end()
56
57 return false
58 }
59
60 res.locals.videoChannel = videoChannel
61 return true
62}