From 866b5d3f5230204d611a556260102996c1aefe10 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Mar 2023 12:01:21 +0100 Subject: Add ability for plugins to alter video jsonld --- server/lib/activitypub/context.ts | 16 ++++++++++------ server/lib/activitypub/send/http.ts | 4 ++-- server/lib/activitypub/send/send-create.ts | 2 +- server/lib/activitypub/send/send-update.ts | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/context.ts b/server/lib/activitypub/context.ts index 349c4d227..a3ca52a31 100644 --- a/server/lib/activitypub/context.ts +++ b/server/lib/activitypub/context.ts @@ -1,7 +1,8 @@ import { ContextType } from '@shared/models' +import { Hooks } from '../plugins/hooks' -function activityPubContextify (data: T, type: ContextType) { - return { ...getContextData(type), ...data } +async function activityPubContextify (data: T, type: ContextType) { + return { ...await getContextData(type), ...data } } // --------------------------------------------------------------------------- @@ -165,10 +166,13 @@ const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string Rate: buildContext() } -function getContextData (type: ContextType) { - return { - '@context': contextStore[type] - } +async function getContextData (type: ContextType) { + const contextData = await Hooks.wrapObject( + contextStore[type], + 'filter:activity-pub.activity.context.build.result' + ) + + return { '@context': contextData } } function buildContext (contextValue?: ContextValue) { diff --git a/server/lib/activitypub/send/http.ts b/server/lib/activitypub/send/http.ts index d8d0b8542..ad7869853 100644 --- a/server/lib/activitypub/send/http.ts +++ b/server/lib/activitypub/send/http.ts @@ -52,9 +52,9 @@ function buildGlobalHeaders (body: any) { } } -function signAndContextify (byActor: MActor, data: T, contextType: ContextType | null) { +async function signAndContextify (byActor: MActor, data: T, contextType: ContextType | null) { const activity = contextType - ? activityPubContextify(data, contextType) + ? await activityPubContextify(data, contextType) : data return signJsonLDObject(byActor, activity) diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 7c3a6bdd0..0e996ab80 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -33,7 +33,7 @@ async function sendCreateVideo (video: MVideoAP, transaction: Transaction) { logger.info('Creating job to send video creation of %s.', video.url, lTags(video.uuid)) const byActor = video.VideoChannel.Account.Actor - const videoObject = video.toActivityPubObject() + const videoObject = await video.toActivityPubObject() const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience) diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 24983dd19..5a66294e6 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -36,7 +36,7 @@ async function sendUpdateVideo (videoArg: MVideoAPWithoutCaption, transaction: T video.VideoCaptions = await video.$get('VideoCaptions', { transaction }) } - const videoObject = video.toActivityPubObject() + const videoObject = await video.toActivityPubObject() const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience) -- cgit v1.2.3