diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-08-25 11:36:23 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-08-25 11:36:23 +0200 |
commit | 93e1258c7cbc0d1235ca6d2a1f7c1875985328b8 (patch) | |
tree | b0a1f77af7ab54dc5f58f569fcd1e9d84b04c533 /server/helpers/custom-validators | |
parent | 69f224587e99d56008e1fa129d0641840a486620 (diff) | |
download | PeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.tar.gz PeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.tar.zst PeerTube-93e1258c7cbc0d1235ca6d2a1f7c1875985328b8.zip |
Move video file metadata in their own table
Will be used for user video quotas and multiple video resolutions
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/remote/videos.ts | 19 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 39 |
2 files changed, 40 insertions, 18 deletions
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts index b33d8c9be..091cd2186 100644 --- a/server/helpers/custom-validators/remote/videos.ts +++ b/server/helpers/custom-validators/remote/videos.ts | |||
@@ -23,10 +23,11 @@ import { | |||
23 | isVideoNSFWValid, | 23 | isVideoNSFWValid, |
24 | isVideoDescriptionValid, | 24 | isVideoDescriptionValid, |
25 | isVideoDurationValid, | 25 | isVideoDurationValid, |
26 | isVideoInfoHashValid, | 26 | isVideoFileInfoHashValid, |
27 | isVideoNameValid, | 27 | isVideoNameValid, |
28 | isVideoTagsValid, | 28 | isVideoTagsValid, |
29 | isVideoExtnameValid | 29 | isVideoFileExtnameValid, |
30 | isVideoFileResolutionValid | ||
30 | } from '../videos' | 31 | } from '../videos' |
31 | 32 | ||
32 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] | 33 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] |
@@ -121,14 +122,22 @@ function isCommonVideoAttributesValid (video: any) { | |||
121 | isVideoNSFWValid(video.nsfw) && | 122 | isVideoNSFWValid(video.nsfw) && |
122 | isVideoDescriptionValid(video.description) && | 123 | isVideoDescriptionValid(video.description) && |
123 | isVideoDurationValid(video.duration) && | 124 | isVideoDurationValid(video.duration) && |
124 | isVideoInfoHashValid(video.infoHash) && | ||
125 | isVideoNameValid(video.name) && | 125 | isVideoNameValid(video.name) && |
126 | isVideoTagsValid(video.tags) && | 126 | isVideoTagsValid(video.tags) && |
127 | isVideoUUIDValid(video.uuid) && | 127 | isVideoUUIDValid(video.uuid) && |
128 | isVideoExtnameValid(video.extname) && | ||
129 | isVideoViewsValid(video.views) && | 128 | isVideoViewsValid(video.views) && |
130 | isVideoLikesValid(video.likes) && | 129 | isVideoLikesValid(video.likes) && |
131 | isVideoDislikesValid(video.dislikes) | 130 | isVideoDislikesValid(video.dislikes) && |
131 | isArray(video.files) && | ||
132 | video.files.every(videoFile => { | ||
133 | if (!videoFile) return false | ||
134 | |||
135 | return ( | ||
136 | isVideoFileInfoHashValid(videoFile.infoHash) && | ||
137 | isVideoFileExtnameValid(videoFile.extname) && | ||
138 | isVideoFileResolutionValid(videoFile.resolution) | ||
139 | ) | ||
140 | }) | ||
132 | } | 141 | } |
133 | 142 | ||
134 | function isRequestTypeAddValid (value: string) { | 143 | function isRequestTypeAddValid (value: string) { |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 62132acb1..139fa760f 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -7,7 +7,8 @@ import { | |||
7 | VIDEO_CATEGORIES, | 7 | VIDEO_CATEGORIES, |
8 | VIDEO_LICENCES, | 8 | VIDEO_LICENCES, |
9 | VIDEO_LANGUAGES, | 9 | VIDEO_LANGUAGES, |
10 | VIDEO_RATE_TYPES | 10 | VIDEO_RATE_TYPES, |
11 | VIDEO_FILE_RESOLUTIONS | ||
11 | } from '../../initializers' | 12 | } from '../../initializers' |
12 | import { isUserUsernameValid } from './users' | 13 | import { isUserUsernameValid } from './users' |
13 | import { isArray, exists } from './misc' | 14 | import { isArray, exists } from './misc' |
@@ -53,14 +54,6 @@ function isVideoDurationValid (value: string) { | |||
53 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) | 54 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) |
54 | } | 55 | } |
55 | 56 | ||
56 | function isVideoExtnameValid (value: string) { | ||
57 | return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1 | ||
58 | } | ||
59 | |||
60 | function isVideoInfoHashValid (value: string) { | ||
61 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) | ||
62 | } | ||
63 | |||
64 | function isVideoNameValid (value: string) { | 57 | function isVideoNameValid (value: string) { |
65 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) | 58 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) |
66 | } | 59 | } |
@@ -128,6 +121,22 @@ function isVideoFile (value: string, files: { [ fieldname: string ]: Express.Mul | |||
128 | return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) | 121 | return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) |
129 | } | 122 | } |
130 | 123 | ||
124 | function isVideoFileSizeValid (value: string) { | ||
125 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) | ||
126 | } | ||
127 | |||
128 | function isVideoFileResolutionValid (value: string) { | ||
129 | return VIDEO_FILE_RESOLUTIONS[value] !== undefined | ||
130 | } | ||
131 | |||
132 | function isVideoFileExtnameValid (value: string) { | ||
133 | return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1 | ||
134 | } | ||
135 | |||
136 | function isVideoFileInfoHashValid (value: string) { | ||
137 | return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) | ||
138 | } | ||
139 | |||
131 | // --------------------------------------------------------------------------- | 140 | // --------------------------------------------------------------------------- |
132 | 141 | ||
133 | export { | 142 | export { |
@@ -140,12 +149,12 @@ export { | |||
140 | isVideoNSFWValid, | 149 | isVideoNSFWValid, |
141 | isVideoDescriptionValid, | 150 | isVideoDescriptionValid, |
142 | isVideoDurationValid, | 151 | isVideoDurationValid, |
143 | isVideoInfoHashValid, | 152 | isVideoFileInfoHashValid, |
144 | isVideoNameValid, | 153 | isVideoNameValid, |
145 | isVideoTagsValid, | 154 | isVideoTagsValid, |
146 | isVideoThumbnailValid, | 155 | isVideoThumbnailValid, |
147 | isVideoThumbnailDataValid, | 156 | isVideoThumbnailDataValid, |
148 | isVideoExtnameValid, | 157 | isVideoFileExtnameValid, |
149 | isVideoUUIDValid, | 158 | isVideoUUIDValid, |
150 | isVideoAbuseReasonValid, | 159 | isVideoAbuseReasonValid, |
151 | isVideoAbuseReporterUsernameValid, | 160 | isVideoAbuseReporterUsernameValid, |
@@ -154,7 +163,9 @@ export { | |||
154 | isVideoLikesValid, | 163 | isVideoLikesValid, |
155 | isVideoRatingTypeValid, | 164 | isVideoRatingTypeValid, |
156 | isVideoDislikesValid, | 165 | isVideoDislikesValid, |
157 | isVideoEventCountValid | 166 | isVideoEventCountValid, |
167 | isVideoFileSizeValid, | ||
168 | isVideoFileResolutionValid | ||
158 | } | 169 | } |
159 | 170 | ||
160 | declare global { | 171 | declare global { |
@@ -183,7 +194,9 @@ declare global { | |||
183 | isVideoLikesValid, | 194 | isVideoLikesValid, |
184 | isVideoRatingTypeValid, | 195 | isVideoRatingTypeValid, |
185 | isVideoDislikesValid, | 196 | isVideoDislikesValid, |
186 | isVideoEventCountValid | 197 | isVideoEventCountValid, |
198 | isVideoFileSizeValid, | ||
199 | isVideoFileResolutionValid | ||
187 | } | 200 | } |
188 | } | 201 | } |
189 | } | 202 | } |