From: Chocobozzz Date: Tue, 21 May 2019 07:31:53 +0000 (+0200) Subject: Relax activity validation X-Git-Tag: v1.3.0-rc.2~6 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4550872bcc8f9ef46183463c7b7b74a90cb6d17c;p=oweals%2Fpeertube.git Relax activity validation --- diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index e0d170d9d..f68c76cdc 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts @@ -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 } = {