diff options
author | Chocobozzz <me@florianbigard.com> | 2020-01-30 11:53:38 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-01-30 11:53:38 +0100 |
commit | ca6d36227a9273f616a462d3aad6a721ab5dd627 (patch) | |
tree | a1610578e719ddb2c58199f06dd4eae436d25c0a /server/helpers/custom-validators | |
parent | 215304eaa06020f27152108567c6a9de16b220d3 (diff) | |
download | PeerTube-ca6d36227a9273f616a462d3aad6a721ab5dd627.tar.gz PeerTube-ca6d36227a9273f616a462d3aad6a721ab5dd627.tar.zst PeerTube-ca6d36227a9273f616a462d3aad6a721ab5dd627.zip |
Add url field in caption and use it for thumbnails
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 224f03f4e..22b5e14a2 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -51,6 +51,10 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { | |||
51 | logger.debug('Video has invalid captions', { video }) | 51 | logger.debug('Video has invalid captions', { video }) |
52 | return false | 52 | return false |
53 | } | 53 | } |
54 | if (!setValidRemoteIcon(video)) { | ||
55 | logger.debug('Video has invalid icons', { video }) | ||
56 | return false | ||
57 | } | ||
54 | 58 | ||
55 | // Default attributes | 59 | // Default attributes |
56 | if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED | 60 | if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED |
@@ -73,7 +77,6 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { | |||
73 | isDateValid(video.updated) && | 77 | isDateValid(video.updated) && |
74 | (!video.originallyPublishedAt || isDateValid(video.originallyPublishedAt)) && | 78 | (!video.originallyPublishedAt || isDateValid(video.originallyPublishedAt)) && |
75 | (!video.content || isRemoteVideoContentValid(video.mediaType, video.content)) && | 79 | (!video.content || isRemoteVideoContentValid(video.mediaType, video.content)) && |
76 | isRemoteVideoIconValid(video.icon) && | ||
77 | video.url.length !== 0 && | 80 | video.url.length !== 0 && |
78 | video.attributedTo.length !== 0 | 81 | video.attributedTo.length !== 0 |
79 | } | 82 | } |
@@ -132,6 +135,8 @@ function setValidRemoteCaptions (video: any) { | |||
132 | if (Array.isArray(video.subtitleLanguage) === false) return false | 135 | if (Array.isArray(video.subtitleLanguage) === false) return false |
133 | 136 | ||
134 | video.subtitleLanguage = video.subtitleLanguage.filter(caption => { | 137 | video.subtitleLanguage = video.subtitleLanguage.filter(caption => { |
138 | if (!isActivityPubUrlValid(caption.url)) caption.url = null | ||
139 | |||
135 | return isRemoteStringIdentifierValid(caption) | 140 | return isRemoteStringIdentifierValid(caption) |
136 | }) | 141 | }) |
137 | 142 | ||
@@ -150,12 +155,19 @@ function isRemoteVideoContentValid (mediaType: string, content: string) { | |||
150 | return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content) | 155 | return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content) |
151 | } | 156 | } |
152 | 157 | ||
153 | function isRemoteVideoIconValid (icon: any) { | 158 | function setValidRemoteIcon (video: any) { |
154 | return icon.type === 'Image' && | 159 | if (video.icon && !isArray(video.icon)) video.icon = [ video.icon ] |
155 | isActivityPubUrlValid(icon.url) && | 160 | if (!video.icon) video.icon = [] |
156 | icon.mediaType === 'image/jpeg' && | 161 | |
157 | validator.isInt(icon.width + '', { min: 0 }) && | 162 | video.icon = video.icon.filter(icon => { |
158 | validator.isInt(icon.height + '', { min: 0 }) | 163 | return icon.type === 'Image' && |
164 | isActivityPubUrlValid(icon.url) && | ||
165 | icon.mediaType === 'image/jpeg' && | ||
166 | validator.isInt(icon.width + '', { min: 0 }) && | ||
167 | validator.isInt(icon.height + '', { min: 0 }) | ||
168 | }) | ||
169 | |||
170 | return video.icon.length !== 0 | ||
159 | } | 171 | } |
160 | 172 | ||
161 | function setValidRemoteVideoUrls (video: any) { | 173 | function setValidRemoteVideoUrls (video: any) { |