aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/activitypub/activity.ts6
-rw-r--r--server/helpers/custom-validators/activitypub/misc.ts2
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts42
3 files changed, 31 insertions, 19 deletions
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts
index 08e5ae0aa..8084cf7b0 100644
--- a/server/helpers/custom-validators/activitypub/activity.ts
+++ b/server/helpers/custom-validators/activitypub/activity.ts
@@ -2,8 +2,7 @@ import * as validator from 'validator'
2import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' 2import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account'
3import { isActivityPubUrlValid } from './misc' 3import { isActivityPubUrlValid } from './misc'
4import { 4import {
5 isVideoAnnounceValid, 5 isAnnounceValid,
6 isVideoChannelAnnounceValid,
7 isVideoChannelCreateActivityValid, 6 isVideoChannelCreateActivityValid,
8 isVideoChannelDeleteActivityValid, 7 isVideoChannelDeleteActivityValid,
9 isVideoChannelUpdateActivityValid, 8 isVideoChannelUpdateActivityValid,
@@ -37,8 +36,7 @@ function isActivityValid (activity: any) {
37 isAccountFollowActivityValid(activity) || 36 isAccountFollowActivityValid(activity) ||
38 isAccountAcceptActivityValid(activity) || 37 isAccountAcceptActivityValid(activity) ||
39 isVideoFlagValid(activity) || 38 isVideoFlagValid(activity) ||
40 isVideoAnnounceValid(activity) || 39 isAnnounceValid(activity)
41 isVideoChannelAnnounceValid(activity)
42} 40}
43 41
44// --------------------------------------------------------------------------- 42// ---------------------------------------------------------------------------
diff --git a/server/helpers/custom-validators/activitypub/misc.ts b/server/helpers/custom-validators/activitypub/misc.ts
index 665a63a73..f09a764b6 100644
--- a/server/helpers/custom-validators/activitypub/misc.ts
+++ b/server/helpers/custom-validators/activitypub/misc.ts
@@ -21,7 +21,7 @@ function isActivityPubUrlValid (url: string) {
21} 21}
22 22
23function isBaseActivityValid (activity: any, type: string) { 23function isBaseActivityValid (activity: any, type: string) {
24 return Array.isArray(activity['@context']) && 24 return (activity['@context'] === undefined || Array.isArray(activity['@context'])) &&
25 activity.type === type && 25 activity.type === type &&
26 isActivityPubUrlValid(activity.id) && 26 isActivityPubUrlValid(activity.id) &&
27 isActivityPubUrlValid(activity.actor) && 27 isActivityPubUrlValid(activity.actor) &&
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index 89c49b0df..8486297ad 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -39,6 +39,7 @@ function isActivityPubVideoDurationValid (value: string) {
39 39
40function isVideoTorrentObjectValid (video: any) { 40function isVideoTorrentObjectValid (video: any) {
41 return video.type === 'Video' && 41 return video.type === 'Video' &&
42 isActivityPubUrlValid(video.id) &&
42 isVideoNameValid(video.name) && 43 isVideoNameValid(video.name) &&
43 isActivityPubVideoDurationValid(video.duration) && 44 isActivityPubVideoDurationValid(video.duration) &&
44 isUUIDValid(video.uuid) && 45 isUUIDValid(video.uuid) &&
@@ -62,14 +63,12 @@ function isVideoFlagValid (activity: any) {
62 isActivityPubUrlValid(activity.object) 63 isActivityPubUrlValid(activity.object)
63} 64}
64 65
65function isVideoAnnounceValid (activity: any) { 66function isAnnounceValid (activity: any) {
66 return isBaseActivityValid(activity, 'Announce') && 67 return isBaseActivityValid(activity, 'Announce') &&
67 isVideoTorrentObjectValid(activity.object) 68 (
68} 69 isVideoChannelCreateActivityValid(activity.object) ||
69 70 isVideoTorrentAddActivityValid(activity.object)
70function isVideoChannelAnnounceValid (activity: any) { 71 )
71 return isBaseActivityValid(activity, 'Announce') &&
72 isVideoChannelObjectValid(activity.object)
73} 72}
74 73
75function isVideoChannelCreateActivityValid (activity: any) { 74function isVideoChannelCreateActivityValid (activity: any) {
@@ -88,8 +87,11 @@ function isVideoChannelDeleteActivityValid (activity: any) {
88 87
89function isVideoChannelObjectValid (videoChannel: any) { 88function isVideoChannelObjectValid (videoChannel: any) {
90 return videoChannel.type === 'VideoChannel' && 89 return videoChannel.type === 'VideoChannel' &&
90 isActivityPubUrlValid(videoChannel.id) &&
91 isVideoChannelNameValid(videoChannel.name) && 91 isVideoChannelNameValid(videoChannel.name) &&
92 isVideoChannelDescriptionValid(videoChannel.description) && 92 isVideoChannelDescriptionValid(videoChannel.content) &&
93 isDateValid(videoChannel.published) &&
94 isDateValid(videoChannel.updated) &&
93 isUUIDValid(videoChannel.uuid) 95 isUUIDValid(videoChannel.uuid)
94} 96}
95 97
@@ -103,8 +105,8 @@ export {
103 isVideoChannelDeleteActivityValid, 105 isVideoChannelDeleteActivityValid,
104 isVideoTorrentDeleteActivityValid, 106 isVideoTorrentDeleteActivityValid,
105 isVideoFlagValid, 107 isVideoFlagValid,
106 isVideoAnnounceValid, 108 isAnnounceValid,
107 isVideoChannelAnnounceValid 109 isVideoChannelObjectValid
108} 110}
109 111
110// --------------------------------------------------------------------------- 112// ---------------------------------------------------------------------------
@@ -148,8 +150,20 @@ function setValidRemoteVideoUrls (video: any) {
148 150
149function isRemoteVideoUrlValid (url: any) { 151function isRemoteVideoUrlValid (url: any) {
150 return url.type === 'Link' && 152 return url.type === 'Link' &&
151 ACTIVITY_PUB.VIDEO_URL_MIME_TYPES.indexOf(url.mimeType) !== -1 && 153 (
152 isVideoUrlValid(url.url) && 154 ACTIVITY_PUB.URL_MIME_TYPES.VIDEO.indexOf(url.mimeType) !== -1 &&
153 validator.isInt(url.width + '', { min: 0 }) && 155 isVideoUrlValid(url.url) &&
154 validator.isInt(url.size + '', { min: 0 }) 156 validator.isInt(url.width + '', { min: 0 }) &&
157 validator.isInt(url.size + '', { min: 0 })
158 ) ||
159 (
160 ACTIVITY_PUB.URL_MIME_TYPES.TORRENT.indexOf(url.mimeType) !== -1 &&
161 isVideoUrlValid(url.url) &&
162 validator.isInt(url.width + '', { min: 0 })
163 ) ||
164 (
165 ACTIVITY_PUB.URL_MIME_TYPES.MAGNET.indexOf(url.mimeType) !== -1 &&
166 validator.isLength(url.url, { min: 5 }) &&
167 validator.isInt(url.width + '', { min: 0 })
168 )
155} 169}