diff options
Diffstat (limited to 'server/helpers/custom-validators/video-channels.ts')
-rw-r--r-- | server/helpers/custom-validators/video-channels.ts | 32 |
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' | |||
5 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
6 | import { VideoChannelModel } from '../../models/video/video-channel' | 6 | import { VideoChannelModel } from '../../models/video/video-channel' |
7 | import { exists } from './misc' | 7 | import { exists } from './misc' |
8 | import { Response } from 'express' | ||
8 | 9 | ||
9 | const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS | 10 | const 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 | ||
24 | async function isLocalVideoChannelNameExist (name: string, res: Response) { | ||
25 | const videoChannel = await VideoChannelModel.loadLocalByName(name) | ||
26 | |||
27 | return processVideoChannelExist(videoChannel, res) | ||
28 | } | ||
29 | |||
23 | async function isVideoChannelExist (id: string, res: express.Response) { | 30 | async 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 | ||
45 | export { | 43 | export { |
44 | isLocalVideoChannelNameExist, | ||
46 | isVideoChannelDescriptionValid, | 45 | isVideoChannelDescriptionValid, |
47 | isVideoChannelNameValid, | 46 | isVideoChannelNameValid, |
48 | isVideoChannelSupportValid, | 47 | isVideoChannelSupportValid, |
49 | isVideoChannelExist | 48 | isVideoChannelExist |
50 | } | 49 | } |
50 | |||
51 | function 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 | } | ||