aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r--server/helpers/custom-validators/videos.ts39
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 @@
1import * as Bluebird from 'bluebird'
2import { Response } from 'express' 1import { Response } from 'express'
3import 'express-validator' 2import 'express-validator'
4import { values } from 'lodash' 3import { values } from 'lodash'
@@ -6,12 +5,10 @@ import 'multer'
6import * as validator from 'validator' 5import * as validator from 'validator'
7import { VideoRateType } from '../../../shared' 6import { VideoRateType } from '../../../shared'
8import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_RATE_TYPES } from '../../initializers' 7import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_RATE_TYPES } from '../../initializers'
8import { VIDEO_PRIVACIES } from '../../initializers/constants'
9import { database as db } from '../../initializers/database' 9import { database as db } from '../../initializers/database'
10import { VideoInstance } from '../../models/video/video-interface' 10import { VideoInstance } from '../../models/video/video-interface'
11import { logger } from '../logger'
12import { isActivityPubUrlValid } from './activitypub/misc'
13import { exists, isArray } from './misc' 11import { exists, isArray } from './misc'
14import { VIDEO_PRIVACIES } from '../../initializers/constants'
15 12
16const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 13const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
17const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES 14const 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
23function isVideoUrlValid (value: string) {
24 return isActivityPubUrlValid(value)
25}
26
27function isVideoLicenceValid (value: number) { 20function 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
109function checkVideoExists (id: string, res: Response, callback: () => void) { 102async 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
133async 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}