diff options
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 276354626..f13178c54 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
2 | import { Response } from 'express' | 1 | import { Response } from 'express' |
3 | import 'express-validator' | 2 | import 'express-validator' |
4 | import { values } from 'lodash' | 3 | import { values } from 'lodash' |
@@ -6,12 +5,10 @@ import 'multer' | |||
6 | import * as validator from 'validator' | 5 | import * as validator from 'validator' |
7 | import { VideoRateType } from '../../../shared' | 6 | import { VideoRateType } from '../../../shared' |
8 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_RATE_TYPES } from '../../initializers' | 7 | import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_RATE_TYPES } from '../../initializers' |
8 | import { VIDEO_PRIVACIES } from '../../initializers/constants' | ||
9 | import { database as db } from '../../initializers/database' | 9 | import { database as db } from '../../initializers/database' |
10 | import { VideoInstance } from '../../models/video/video-interface' | 10 | import { VideoInstance } from '../../models/video/video-interface' |
11 | import { logger } from '../logger' | ||
12 | import { isActivityPubUrlValid } from './activitypub/misc' | ||
13 | import { exists, isArray } from './misc' | 11 | import { exists, isArray } from './misc' |
14 | import { VIDEO_PRIVACIES } from '../../initializers/constants' | ||
15 | 12 | ||
16 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | 13 | const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS |
17 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | 14 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES |
@@ -20,10 +17,6 @@ function isVideoCategoryValid (value: number) { | |||
20 | return VIDEO_CATEGORIES[value] !== undefined | 17 | return VIDEO_CATEGORIES[value] !== undefined |
21 | } | 18 | } |
22 | 19 | ||
23 | function isVideoUrlValid (value: string) { | ||
24 | return isActivityPubUrlValid(value) | ||
25 | } | ||
26 | |||
27 | function isVideoLicenceValid (value: number) { | 20 | function isVideoLicenceValid (value: number) { |
28 | return VIDEO_LICENCES[value] !== undefined | 21 | return VIDEO_LICENCES[value] !== undefined |
29 | } | 22 | } |
@@ -106,31 +99,7 @@ function isVideoFileSizeValid (value: string) { | |||
106 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) | 99 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) |
107 | } | 100 | } |
108 | 101 | ||
109 | function checkVideoExists (id: string, res: Response, callback: () => void) { | 102 | async function isVideoExist (id: string, res: Response) { |
110 | let promise: Bluebird<VideoInstance> | ||
111 | if (validator.isInt(id)) { | ||
112 | promise = db.Video.loadAndPopulateAccountAndServerAndTags(+id) | ||
113 | } else { // UUID | ||
114 | promise = db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(id) | ||
115 | } | ||
116 | |||
117 | promise.then(video => { | ||
118 | if (!video) { | ||
119 | return res.status(404) | ||
120 | .json({ error: 'Video not found' }) | ||
121 | .end() | ||
122 | } | ||
123 | |||
124 | res.locals.video = video | ||
125 | callback() | ||
126 | }) | ||
127 | .catch(err => { | ||
128 | logger.error('Error in video request validator.', err) | ||
129 | return res.sendStatus(500) | ||
130 | }) | ||
131 | } | ||
132 | |||
133 | async function isVideoExistsPromise (id: string, res: Response) { | ||
134 | let video: VideoInstance | 103 | let video: VideoInstance |
135 | 104 | ||
136 | if (validator.isInt(id)) { | 105 | if (validator.isInt(id)) { |
@@ -169,10 +138,8 @@ export { | |||
169 | isVideoRatingTypeValid, | 138 | isVideoRatingTypeValid, |
170 | isVideoDurationValid, | 139 | isVideoDurationValid, |
171 | isVideoTagValid, | 140 | isVideoTagValid, |
172 | isVideoUrlValid, | ||
173 | isVideoPrivacyValid, | 141 | isVideoPrivacyValid, |
174 | isVideoFileResolutionValid, | 142 | isVideoFileResolutionValid, |
175 | isVideoFileSizeValid, | 143 | isVideoFileSizeValid, |
176 | checkVideoExists, | 144 | isVideoExist |
177 | isVideoExistsPromise | ||
178 | } | 145 | } |