aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/activitypub/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/activitypub/videos.ts')
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts49
1 files changed, 26 insertions, 23 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index 0362f43ab..f76eba474 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -75,6 +75,30 @@ function sanitizeAndCheckVideoTorrentObject (video: any) {
75 video.attributedTo.length !== 0 75 video.attributedTo.length !== 0
76} 76}
77 77
78function isRemoteVideoUrlValid (url: any) {
79 // FIXME: Old bug, we used the width to represent the resolution. Remove it in a few release (currently beta.11)
80 if (url.width && !url.height) url.height = url.width
81
82 return url.type === 'Link' &&
83 (
84 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 &&
85 isActivityPubUrlValid(url.href) &&
86 validator.isInt(url.height + '', { min: 0 }) &&
87 validator.isInt(url.size + '', { min: 0 }) &&
88 (!url.fps || validator.isInt(url.fps + '', { min: 0 }))
89 ) ||
90 (
91 ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 &&
92 isActivityPubUrlValid(url.href) &&
93 validator.isInt(url.height + '', { min: 0 })
94 ) ||
95 (
96 ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 &&
97 validator.isLength(url.href, { min: 5 }) &&
98 validator.isInt(url.height + '', { min: 0 })
99 )
100}
101
78// --------------------------------------------------------------------------- 102// ---------------------------------------------------------------------------
79 103
80export { 104export {
@@ -83,7 +107,8 @@ export {
83 isVideoTorrentDeleteActivityValid, 107 isVideoTorrentDeleteActivityValid,
84 isRemoteStringIdentifierValid, 108 isRemoteStringIdentifierValid,
85 isVideoFlagValid, 109 isVideoFlagValid,
86 sanitizeAndCheckVideoTorrentObject 110 sanitizeAndCheckVideoTorrentObject,
111 isRemoteVideoUrlValid
87} 112}
88 113
89// --------------------------------------------------------------------------- 114// ---------------------------------------------------------------------------
@@ -147,26 +172,4 @@ function setRemoteVideoTruncatedContent (video: any) {
147 return true 172 return true
148} 173}
149 174
150function isRemoteVideoUrlValid (url: any) {
151 // FIXME: Old bug, we used the width to represent the resolution. Remove it in a few realease (currently beta.11)
152 if (url.width && !url.height) url.height = url.width
153 175
154 return url.type === 'Link' &&
155 (
156 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 &&
157 isActivityPubUrlValid(url.href) &&
158 validator.isInt(url.height + '', { min: 0 }) &&
159 validator.isInt(url.size + '', { min: 0 }) &&
160 (!url.fps || validator.isInt(url.fps + '', { min: 0 }))
161 ) ||
162 (
163 ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 &&
164 isActivityPubUrlValid(url.href) &&
165 validator.isInt(url.height + '', { min: 0 })
166 ) ||
167 (
168 ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 &&
169 validator.isLength(url.href, { min: 5 }) &&
170 validator.isInt(url.height + '', { min: 0 })
171 )
172}