diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-12 20:04:58 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-12 20:37:51 +0200 |
commit | 2186386cca113506791583cb07d6ccacba7af4e0 (patch) | |
tree | 3c214c0b5fbd64332624267fa6e51fd4a9cf6474 /server/helpers/custom-validators/videos.ts | |
parent | 6ccdf3a23ecec5ba2eeaf487fd1fafdc7606b4bf (diff) | |
download | PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.gz PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.tar.zst PeerTube-2186386cca113506791583cb07d6ccacba7af4e0.zip |
Add concept of video state, and add ability to wait transcoding before
publishing a video
Diffstat (limited to 'server/helpers/custom-validators/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index f365df985..8496e679a 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -10,7 +10,8 @@ import { | |||
10 | VIDEO_LICENCES, | 10 | VIDEO_LICENCES, |
11 | VIDEO_MIMETYPE_EXT, | 11 | VIDEO_MIMETYPE_EXT, |
12 | VIDEO_PRIVACIES, | 12 | VIDEO_PRIVACIES, |
13 | VIDEO_RATE_TYPES | 13 | VIDEO_RATE_TYPES, |
14 | VIDEO_STATES | ||
14 | } from '../../initializers' | 15 | } from '../../initializers' |
15 | import { VideoModel } from '../../models/video/video' | 16 | import { VideoModel } from '../../models/video/video' |
16 | import { exists, isArray, isFileValid } from './misc' | 17 | import { exists, isArray, isFileValid } from './misc' |
@@ -21,11 +22,15 @@ const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS | |||
21 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES | 22 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES |
22 | 23 | ||
23 | function isVideoCategoryValid (value: any) { | 24 | function isVideoCategoryValid (value: any) { |
24 | return value === null || VIDEO_CATEGORIES[value] !== undefined | 25 | return value === null || VIDEO_CATEGORIES[ value ] !== undefined |
26 | } | ||
27 | |||
28 | function isVideoStateValid (value: any) { | ||
29 | return exists(value) && VIDEO_STATES[ value ] !== undefined | ||
25 | } | 30 | } |
26 | 31 | ||
27 | function isVideoLicenceValid (value: any) { | 32 | function isVideoLicenceValid (value: any) { |
28 | return value === null || VIDEO_LICENCES[value] !== undefined | 33 | return value === null || VIDEO_LICENCES[ value ] !== undefined |
29 | } | 34 | } |
30 | 35 | ||
31 | function isVideoLanguageValid (value: any) { | 36 | function isVideoLanguageValid (value: any) { |
@@ -79,20 +84,22 @@ function isVideoRatingTypeValid (value: string) { | |||
79 | 84 | ||
80 | const videoFileTypes = Object.keys(VIDEO_MIMETYPE_EXT).map(m => `(${m})`) | 85 | const videoFileTypes = Object.keys(VIDEO_MIMETYPE_EXT).map(m => `(${m})`) |
81 | const videoFileTypesRegex = videoFileTypes.join('|') | 86 | const videoFileTypesRegex = videoFileTypes.join('|') |
87 | |||
82 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { | 88 | function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[]) { |
83 | return isFileValid(files, videoFileTypesRegex, 'videofile') | 89 | return isFileValid(files, videoFileTypesRegex, 'videofile') |
84 | } | 90 | } |
85 | 91 | ||
86 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME | 92 | const videoImageTypes = CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME |
87 | .map(v => v.replace('.', '')) | 93 | .map(v => v.replace('.', '')) |
88 | .join('|') | 94 | .join('|') |
89 | const videoImageTypesRegex = `image/(${videoImageTypes})` | 95 | const videoImageTypesRegex = `image/(${videoImageTypes})` |
96 | |||
90 | function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { | 97 | function isVideoImage (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { |
91 | return isFileValid(files, videoImageTypesRegex, field, true) | 98 | return isFileValid(files, videoImageTypesRegex, field, true) |
92 | } | 99 | } |
93 | 100 | ||
94 | function isVideoPrivacyValid (value: string) { | 101 | function isVideoPrivacyValid (value: string) { |
95 | return validator.isInt(value + '') && VIDEO_PRIVACIES[value] !== undefined | 102 | return validator.isInt(value + '') && VIDEO_PRIVACIES[ value ] !== undefined |
96 | } | 103 | } |
97 | 104 | ||
98 | function isVideoFileInfoHashValid (value: string) { | 105 | function isVideoFileInfoHashValid (value: string) { |
@@ -118,8 +125,8 @@ async function isVideoExist (id: string, res: Response) { | |||
118 | 125 | ||
119 | if (!video) { | 126 | if (!video) { |
120 | res.status(404) | 127 | res.status(404) |
121 | .json({ error: 'Video not found' }) | 128 | .json({ error: 'Video not found' }) |
122 | .end() | 129 | .end() |
123 | 130 | ||
124 | return false | 131 | return false |
125 | } | 132 | } |
@@ -169,6 +176,7 @@ export { | |||
169 | isVideoTagsValid, | 176 | isVideoTagsValid, |
170 | isVideoAbuseReasonValid, | 177 | isVideoAbuseReasonValid, |
171 | isVideoFile, | 178 | isVideoFile, |
179 | isVideoStateValid, | ||
172 | isVideoViewsValid, | 180 | isVideoViewsValid, |
173 | isVideoRatingTypeValid, | 181 | isVideoRatingTypeValid, |
174 | isVideoDurationValid, | 182 | isVideoDurationValid, |