diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-15 16:28:35 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 8e10cf1a5a438a00e5f7e0691cb830769867cffc (patch) | |
tree | 23c0aeb43d7fb05b2d280c37b4334c2f320b647e /server/helpers/custom-validators | |
parent | 8e13fa7d09e9925b4559cbba6c5d72c5ff1bd391 (diff) | |
download | PeerTube-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.ts | 30 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 15 |
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 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | 2 | import { ACTIVITY_PUB } from '../../../initializers' | |
3 | import { | 3 | import { exists, isDateValid, isUUIDValid } from '../misc' |
4 | ACTIVITY_PUB | 4 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' |
5 | } from '../../../initializers' | ||
6 | import { isDateValid, isUUIDValid } from '../misc' | ||
7 | import { | 5 | import { |
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' |
16 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' | 14 | import { isBaseActivityValid } from './misc' |
17 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' | ||
18 | 15 | ||
19 | function isVideoTorrentAddActivityValid (activity: any) { | 16 | function 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 | ||
30 | function 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 | |||
33 | function isVideoTorrentObjectValid (video: any) { | 39 | function 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 | ||
72 | function isVideoDurationValid (value: string) { | ||
73 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) | ||
74 | } | ||
75 | |||
72 | function isVideoTruncatedDescriptionValid (value: string) { | 76 | function 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 | ||
80 | function 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 | |||
89 | function isVideoNameValid (value: string) { | 84 | function 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, |