aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-03-10 12:01:21 +0100
committerChocobozzz <me@florianbigard.com>2023-03-10 14:42:18 +0100
commit866b5d3f5230204d611a556260102996c1aefe10 (patch)
treed6d1e900ce81a7f1edc121089c10a67abba855eb /server/lib
parent4265d90b0061399e23b816e3880ee1be47ead96f (diff)
downloadPeerTube-866b5d3f5230204d611a556260102996c1aefe10.tar.gz
PeerTube-866b5d3f5230204d611a556260102996c1aefe10.tar.zst
PeerTube-866b5d3f5230204d611a556260102996c1aefe10.zip
Add ability for plugins to alter video jsonld
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/context.ts16
-rw-r--r--server/lib/activitypub/send/http.ts4
-rw-r--r--server/lib/activitypub/send/send-create.ts2
-rw-r--r--server/lib/activitypub/send/send-update.ts2
4 files changed, 14 insertions, 10 deletions
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 @@
1import { ContextType } from '@shared/models' 1import { ContextType } from '@shared/models'
2import { Hooks } from '../plugins/hooks'
2 3
3function activityPubContextify <T> (data: T, type: ContextType) { 4async function activityPubContextify <T> (data: T, type: ContextType) {
4 return { ...getContextData(type), ...data } 5 return { ...await getContextData(type), ...data }
5} 6}
6 7
7// --------------------------------------------------------------------------- 8// ---------------------------------------------------------------------------
@@ -165,10 +166,13 @@ const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string
165 Rate: buildContext() 166 Rate: buildContext()
166} 167}
167 168
168function getContextData (type: ContextType) { 169async function getContextData (type: ContextType) {
169 return { 170 const contextData = await Hooks.wrapObject(
170 '@context': contextStore[type] 171 contextStore[type],
171 } 172 'filter:activity-pub.activity.context.build.result'
173 )
174
175 return { '@context': contextData }
172} 176}
173 177
174function buildContext (contextValue?: ContextValue) { 178function 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) {
52 } 52 }
53} 53}
54 54
55function signAndContextify <T> (byActor: MActor, data: T, contextType: ContextType | null) { 55async function signAndContextify <T> (byActor: MActor, data: T, contextType: ContextType | null) {
56 const activity = contextType 56 const activity = contextType
57 ? activityPubContextify(data, contextType) 57 ? await activityPubContextify(data, contextType)
58 : data 58 : data
59 59
60 return signJsonLDObject(byActor, activity) 60 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) {
33 logger.info('Creating job to send video creation of %s.', video.url, lTags(video.uuid)) 33 logger.info('Creating job to send video creation of %s.', video.url, lTags(video.uuid))
34 34
35 const byActor = video.VideoChannel.Account.Actor 35 const byActor = video.VideoChannel.Account.Actor
36 const videoObject = video.toActivityPubObject() 36 const videoObject = await video.toActivityPubObject()
37 37
38 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) 38 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
39 const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience) 39 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
36 video.VideoCaptions = await video.$get('VideoCaptions', { transaction }) 36 video.VideoCaptions = await video.$get('VideoCaptions', { transaction })
37 } 37 }
38 38
39 const videoObject = video.toActivityPubObject() 39 const videoObject = await video.toActivityPubObject()
40 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) 40 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
41 41
42 const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience) 42 const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience)