]>
Commit | Line | Data |
---|---|---|
72c7248b C |
1 | import * as express from 'express' |
2 | import 'express-validator' | |
3 | import 'multer' | |
4e50b6a1 | 4 | import * as validator from 'validator' |
3fd3ab2d C |
5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
6 | import { VideoChannelModel } from '../../models/video/video-channel' | |
4e50b6a1 | 7 | import { exists } from './misc' |
72c7248b C |
8 | |
9 | const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS | |
10 | ||
11 | function isVideoChannelDescriptionValid (value: string) { | |
12 | return value === null || validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.DESCRIPTION) | |
13 | } | |
14 | ||
15 | function isVideoChannelNameValid (value: string) { | |
16 | return exists(value) && validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.NAME) | |
17 | } | |
18 | ||
a2431b7d | 19 | async function isVideoChannelExist (id: string, res: express.Response) { |
3fd3ab2d | 20 | let videoChannel: VideoChannelModel |
4e50b6a1 | 21 | if (validator.isInt(id)) { |
3fd3ab2d | 22 | videoChannel = await VideoChannelModel.loadAndPopulateAccount(+id) |
4e50b6a1 | 23 | } else { // UUID |
3fd3ab2d | 24 | videoChannel = await VideoChannelModel.loadByUUIDAndPopulateAccount(id) |
4e50b6a1 C |
25 | } |
26 | ||
27 | if (!videoChannel) { | |
28 | res.status(404) | |
29 | .json({ error: 'Video channel not found' }) | |
30 | .end() | |
31 | ||
32 | return false | |
33 | } | |
34 | ||
35 | res.locals.videoChannel = videoChannel | |
36 | return true | |
37 | } | |
38 | ||
72c7248b C |
39 | // --------------------------------------------------------------------------- |
40 | ||
41 | export { | |
42 | isVideoChannelDescriptionValid, | |
4e50b6a1 | 43 | isVideoChannelNameValid, |
a2431b7d | 44 | isVideoChannelExist |
72c7248b | 45 | } |