Relax activity validation
authorChocobozzz <me@florianbigard.com>
Tue, 21 May 2019 07:31:53 +0000 (09:31 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 21 May 2019 07:31:53 +0000 (09:31 +0200)
server/helpers/custom-validators/activitypub/activity.ts

index e0d170d9d230d175ad01769f78e11b2c65d0887e..f68c76cdcc30917a462ccb673d2f05863bbecd45 100644 (file)
@@ -12,18 +12,19 @@ import { isFlagActivityValid } from './flag'
 import { isPlaylistObjectValid } from './playlist'
 
 function isRootActivityValid (activity: any) {
-  return Array.isArray(activity['@context']) && (
-    (
-      (activity.type === 'Collection' || activity.type === 'OrderedCollection') &&
-      validator.isInt(activity.totalItems, { min: 0 }) &&
-      Array.isArray(activity.items)
-    ) ||
-    (
-      isActivityPubUrlValid(activity.id) &&
-      exists(activity.actor) &&
-      (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id))
-    )
-  )
+  return isCollection(activity) || isActivity(activity)
+}
+
+function isCollection (activity: any) {
+  return (activity.type === 'Collection' || activity.type === 'OrderedCollection') &&
+    validator.isInt(activity.totalItems, { min: 0 }) &&
+    Array.isArray(activity.items)
+}
+
+function isActivity (activity: any) {
+  return isActivityPubUrlValid(activity.id) &&
+    exists(activity.actor) &&
+    (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id))
 }
 
 const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean } = {