diff options
author | Chocobozzz <me@florianbigard.com> | 2023-06-01 14:51:16 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-06-29 10:16:55 +0200 |
commit | d8f39b126d9fe4bec1c12fb213548cc6edc87867 (patch) | |
tree | 7f0f1cb23165cf4dd789b2d78b1fef7ee116f647 /server/helpers/custom-validators/activitypub | |
parent | 1fb7d094229acdc190c3f7551b43ac5445814dee (diff) | |
download | PeerTube-d8f39b126d9fe4bec1c12fb213548cc6edc87867.tar.gz PeerTube-d8f39b126d9fe4bec1c12fb213548cc6edc87867.tar.zst PeerTube-d8f39b126d9fe4bec1c12fb213548cc6edc87867.zip |
Add storyboard support
Diffstat (limited to 'server/helpers/custom-validators/activitypub')
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 97b3577af..573a29754 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import validator from 'validator' | 1 | import validator from 'validator' |
2 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
3 | import { ActivityTrackerUrlObject, ActivityVideoFileMetadataUrlObject } from '@shared/models' | 3 | import { ActivityPubStoryboard, ActivityTrackerUrlObject, ActivityVideoFileMetadataUrlObject, VideoObject } from '@shared/models' |
4 | import { LiveVideoLatencyMode, VideoState } from '../../../../shared/models/videos' | 4 | import { LiveVideoLatencyMode, VideoState } from '../../../../shared/models/videos' |
5 | import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers/constants' | 5 | import { ACTIVITY_PUB, CONSTRAINTS_FIELDS } from '../../../initializers/constants' |
6 | import { peertubeTruncate } from '../../core-utils' | 6 | import { peertubeTruncate } from '../../core-utils' |
@@ -48,6 +48,10 @@ function sanitizeAndCheckVideoTorrentObject (video: any) { | |||
48 | logger.debug('Video has invalid icons', { video }) | 48 | logger.debug('Video has invalid icons', { video }) |
49 | return false | 49 | return false |
50 | } | 50 | } |
51 | if (!setValidStoryboard(video)) { | ||
52 | logger.debug('Video has invalid preview (storyboard)', { video }) | ||
53 | return false | ||
54 | } | ||
51 | 55 | ||
52 | // Default attributes | 56 | // Default attributes |
53 | if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED | 57 | if (!isVideoStateValid(video.state)) video.state = VideoState.PUBLISHED |
@@ -201,3 +205,36 @@ function setRemoteVideoContent (video: any) { | |||
201 | 205 | ||
202 | return true | 206 | return true |
203 | } | 207 | } |
208 | |||
209 | function setValidStoryboard (video: VideoObject) { | ||
210 | if (!video.preview) return true | ||
211 | if (!Array.isArray(video.preview)) return false | ||
212 | |||
213 | video.preview = video.preview.filter(p => isStorybordValid(p)) | ||
214 | |||
215 | return true | ||
216 | } | ||
217 | |||
218 | function isStorybordValid (preview: ActivityPubStoryboard) { | ||
219 | if (!preview) return false | ||
220 | |||
221 | if ( | ||
222 | preview.type !== 'Image' || | ||
223 | !isArray(preview.rel) || | ||
224 | !preview.rel.includes('storyboard') | ||
225 | ) { | ||
226 | return false | ||
227 | } | ||
228 | |||
229 | preview.url = preview.url.filter(u => { | ||
230 | return u.mediaType === 'image/jpeg' && | ||
231 | isActivityPubUrlValid(u.href) && | ||
232 | validator.isInt(u.width + '', { min: 0 }) && | ||
233 | validator.isInt(u.height + '', { min: 0 }) && | ||
234 | validator.isInt(u.tileWidth + '', { min: 0 }) && | ||
235 | validator.isInt(u.tileHeight + '', { min: 0 }) && | ||
236 | isActivityPubVideoDurationValid(u.tileDuration) | ||
237 | }) | ||
238 | |||
239 | return preview.url.length !== 0 | ||
240 | } | ||