aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/activitypub/videos.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-27 17:30:46 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:43:01 +0100
commita2431b7dcbc72c05101dcdbe631ff84a823aeb51 (patch)
tree09278a822905622a70ff976a75e09d99bc45639a /server/helpers/custom-validators/activitypub/videos.ts
parentfcaf1e0aa84213a1b1f1b1a44a3276eae35ebe70 (diff)
downloadPeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.gz
PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.tar.zst
PeerTube-a2431b7dcbc72c05101dcdbe631ff84a823aeb51.zip
Refractor validators
Diffstat (limited to 'server/helpers/custom-validators/activitypub/videos.ts')
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts13
1 files changed, 5 insertions, 8 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index 55e79c4e8..12c672fd2 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -8,7 +8,6 @@ import {
8 isVideoNSFWValid, 8 isVideoNSFWValid,
9 isVideoTagValid, 9 isVideoTagValid,
10 isVideoTruncatedDescriptionValid, 10 isVideoTruncatedDescriptionValid,
11 isVideoUrlValid,
12 isVideoViewsValid 11 isVideoViewsValid
13} from '../videos' 12} from '../videos'
14import { isActivityPubUrlValid, isBaseActivityValid } from './misc' 13import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
@@ -77,12 +76,11 @@ export {
77function setValidRemoteTags (video: any) { 76function setValidRemoteTags (video: any) {
78 if (Array.isArray(video.tag) === false) return false 77 if (Array.isArray(video.tag) === false) return false
79 78
80 const newTag = video.tag.filter(t => { 79 video.tag = video.tag.filter(t => {
81 return t.type === 'Hashtag' && 80 return t.type === 'Hashtag' &&
82 isVideoTagValid(t.name) 81 isVideoTagValid(t.name)
83 }) 82 })
84 83
85 video.tag = newTag
86 return true 84 return true
87} 85}
88 86
@@ -96,7 +94,7 @@ function isRemoteVideoContentValid (mediaType: string, content: string) {
96 94
97function isRemoteVideoIconValid (icon: any) { 95function isRemoteVideoIconValid (icon: any) {
98 return icon.type === 'Image' && 96 return icon.type === 'Image' &&
99 isVideoUrlValid(icon.url) && 97 isActivityPubUrlValid(icon.url) &&
100 icon.mediaType === 'image/jpeg' && 98 icon.mediaType === 'image/jpeg' &&
101 validator.isInt(icon.width + '', { min: 0 }) && 99 validator.isInt(icon.width + '', { min: 0 }) &&
102 validator.isInt(icon.height + '', { min: 0 }) 100 validator.isInt(icon.height + '', { min: 0 })
@@ -105,8 +103,7 @@ function isRemoteVideoIconValid (icon: any) {
105function setValidRemoteVideoUrls (video: any) { 103function setValidRemoteVideoUrls (video: any) {
106 if (Array.isArray(video.url) === false) return false 104 if (Array.isArray(video.url) === false) return false
107 105
108 const newUrl = video.url.filter(u => isRemoteVideoUrlValid(u)) 106 video.url = video.url.filter(u => isRemoteVideoUrlValid(u))
109 video.url = newUrl
110 107
111 return true 108 return true
112} 109}
@@ -115,13 +112,13 @@ function isRemoteVideoUrlValid (url: any) {
115 return url.type === 'Link' && 112 return url.type === 'Link' &&
116 ( 113 (
117 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 && 114 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 &&
118 isVideoUrlValid(url.url) && 115 isActivityPubUrlValid(url.url) &&
119 validator.isInt(url.width + '', { min: 0 }) && 116 validator.isInt(url.width + '', { min: 0 }) &&
120 validator.isInt(url.size + '', { min: 0 }) 117 validator.isInt(url.size + '', { min: 0 })
121 ) || 118 ) ||
122 ( 119 (
123 ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 && 120 ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 &&
124 isVideoUrlValid(url.url) && 121 isActivityPubUrlValid(url.url) &&
125 validator.isInt(url.width + '', { min: 0 }) 122 validator.isInt(url.width + '', { min: 0 })
126 ) || 123 ) ||
127 ( 124 (