From 6be84cbcea99518e8eca58c76259effd0dd992fd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Mar 2018 18:40:33 +0100 Subject: Improve activity pub actors implementation --- server/helpers/activitypub.ts | 9 ++++++++- server/helpers/custom-validators/activitypub/activity.ts | 2 +- server/helpers/custom-validators/activitypub/misc.ts | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index d64a6dd78..1934fa0f0 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts @@ -1,5 +1,5 @@ import { ResultList } from '../../shared/models' -import { Activity } from '../../shared/models/activitypub' +import { Activity, ActivityPubActor } from '../../shared/models/activitypub' import { ACTIVITY_PUB } from '../initializers' import { ActorModel } from '../models/activitypub/actor' import { signObject } from './peertube-crypto' @@ -98,9 +98,16 @@ function buildSignedActivity (byActor: ActorModel, data: Object) { return signObject(byActor, activity) as Promise } +function getActorUrl (activityActor: string | ActivityPubActor) { + if (typeof activityActor === 'string') return activityActor + + return activityActor.id +} + // --------------------------------------------------------------------------- export { + getActorUrl, activityPubContextify, activityPubCollectionPagination, activityPubCollection, diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index 632f14223..7e4dccefb 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts @@ -26,7 +26,7 @@ function isRootActivityValid (activity: any) { ) || ( isActivityPubUrlValid(activity.id) && - isActivityPubUrlValid(activity.actor) + (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id)) ) } diff --git a/server/helpers/custom-validators/activitypub/misc.ts b/server/helpers/custom-validators/activitypub/misc.ts index 75d308e9d..2dac8e1ad 100644 --- a/server/helpers/custom-validators/activitypub/misc.ts +++ b/server/helpers/custom-validators/activitypub/misc.ts @@ -24,7 +24,7 @@ function isBaseActivityValid (activity: any, type: string) { return (activity['@context'] === undefined || Array.isArray(activity['@context'])) && activity.type === type && isActivityPubUrlValid(activity.id) && - isActivityPubUrlValid(activity.actor) && + (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id)) && ( activity.to === undefined || (Array.isArray(activity.to) && activity.to.every(t => isActivityPubUrlValid(t))) -- cgit v1.2.3