aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-15 16:28:35 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit8e10cf1a5a438a00e5f7e0691cb830769867cffc (patch)
tree23c0aeb43d7fb05b2d280c37b4334c2f320b647e /server/helpers/custom-validators
parent8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391 (diff)
downloadPeerTube-8e10cf1a5a438a00e5f7e0691cb830769867cffc.tar.gz
PeerTube-8e10cf1a5a438a00e5f7e0691cb830769867cffc.tar.zst
PeerTube-8e10cf1a5a438a00e5f7e0691cb830769867cffc.zip
Fix video upload and videos list
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts30
-rw-r--r--server/helpers/custom-validators/videos.ts15
2 files changed, 23 insertions, 22 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index c9ecf1f3d..a46757397 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -1,20 +1,17 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2 2import { ACTIVITY_PUB } from '../../../initializers'
3import { 3import { exists, isDateValid, isUUIDValid } from '../misc'
4 ACTIVITY_PUB 4import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
5} from '../../../initializers'
6import { isDateValid, isUUIDValid } from '../misc'
7import { 5import {
8 isVideoViewsValid,
9 isVideoNSFWValid,
10 isVideoTruncatedDescriptionValid,
11 isVideoDurationValid, 6 isVideoDurationValid,
12 isVideoNameValid, 7 isVideoNameValid,
8 isVideoNSFWValid,
13 isVideoTagValid, 9 isVideoTagValid,
14 isVideoUrlValid 10 isVideoTruncatedDescriptionValid,
11 isVideoUrlValid,
12 isVideoViewsValid
15} from '../videos' 13} from '../videos'
16import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' 14import { isBaseActivityValid } from './misc'
17import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
18 15
19function isVideoTorrentAddActivityValid (activity: any) { 16function isVideoTorrentAddActivityValid (activity: any) {
20 return isBaseActivityValid(activity, 'Add') && 17 return isBaseActivityValid(activity, 'Add') &&
@@ -30,10 +27,19 @@ function isVideoTorrentDeleteActivityValid (activity: any) {
30 return isBaseActivityValid(activity, 'Delete') 27 return isBaseActivityValid(activity, 'Delete')
31} 28}
32 29
30function isActivityPubVideoDurationValid (value: string) {
31 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
32 return exists(value) &&
33 typeof value === 'string' &&
34 value.startsWith('PT') &&
35 value.endsWith('S') &&
36 isVideoDurationValid(value.replace(/[^0-9]+/, ''))
37}
38
33function isVideoTorrentObjectValid (video: any) { 39function isVideoTorrentObjectValid (video: any) {
34 return video.type === 'Video' && 40 return video.type === 'Video' &&
35 isVideoNameValid(video.name) && 41 isVideoNameValid(video.name) &&
36 isVideoDurationValid(video.duration) && 42 isActivityPubVideoDurationValid(video.duration) &&
37 isUUIDValid(video.uuid) && 43 isUUIDValid(video.uuid) &&
38 setValidRemoteTags(video) && 44 setValidRemoteTags(video) &&
39 isRemoteIdentifierValid(video.category) && 45 isRemoteIdentifierValid(video.category) &&
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index 1505632da..c97c9a2ad 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -69,6 +69,10 @@ function isVideoNSFWValid (value: any) {
69 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) 69 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
70} 70}
71 71
72function isVideoDurationValid (value: string) {
73 return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION)
74}
75
72function isVideoTruncatedDescriptionValid (value: string) { 76function isVideoTruncatedDescriptionValid (value: string) {
73 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.TRUNCATED_DESCRIPTION) 77 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.TRUNCATED_DESCRIPTION)
74} 78}
@@ -77,15 +81,6 @@ function isVideoDescriptionValid (value: string) {
77 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION) 81 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
78} 82}
79 83
80function isVideoDurationValid (value: string) {
81 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
82 return exists(value) &&
83 typeof value === 'string' &&
84 value.startsWith('PT') &&
85 value.endsWith('S') &&
86 validator.isInt(value.replace(/[^0-9]+/, ''), VIDEOS_CONSTRAINTS_FIELDS.DURATION)
87}
88
89function isVideoNameValid (value: string) { 84function isVideoNameValid (value: string) {
90 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) 85 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME)
91} 86}
@@ -197,7 +192,6 @@ export {
197 isVideoNSFWValid, 192 isVideoNSFWValid,
198 isVideoTruncatedDescriptionValid, 193 isVideoTruncatedDescriptionValid,
199 isVideoDescriptionValid, 194 isVideoDescriptionValid,
200 isVideoDurationValid,
201 isVideoFileInfoHashValid, 195 isVideoFileInfoHashValid,
202 isVideoNameValid, 196 isVideoNameValid,
203 isVideoTagsValid, 197 isVideoTagsValid,
@@ -214,6 +208,7 @@ export {
214 isVideoFileSizeValid, 208 isVideoFileSizeValid,
215 isVideoPrivacyValid, 209 isVideoPrivacyValid,
216 isRemoteVideoPrivacyValid, 210 isRemoteVideoPrivacyValid,
211 isVideoDurationValid,
217 isVideoFileResolutionValid, 212 isVideoFileResolutionValid,
218 checkVideoExists, 213 checkVideoExists,
219 isVideoTagValid, 214 isVideoTagValid,