1 import { ContextType } from '@shared/models'
2 import { Hooks } from '../plugins/hooks'
4 async function activityPubContextify <T> (data: T, type: ContextType) {
5 return { ...await getContextData(type), ...data }
8 // ---------------------------------------------------------------------------
15 // ---------------------------------------------------------------------------
17 type ContextValue = { [ id: string ]: (string | { '@type': string, '@id': string }) }
19 const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string })[] } = {
21 Hashtag: 'as:Hashtag',
22 uuid: 'sc:identifier',
23 category: 'sc:category',
24 licence: 'sc:license',
25 subtitleLanguage: 'sc:subtitleLanguage',
26 sensitive: 'as:sensitive',
27 language: 'sc:inLanguage',
28 identifier: 'sc:identifier',
30 // TODO: remove in a few versions, introduced in 4.2
33 isLiveBroadcast: 'sc:isLiveBroadcast',
35 '@type': 'sc:Boolean',
36 '@id': 'pt:liveSaveReplay'
39 '@type': 'sc:Boolean',
40 '@id': 'pt:permanentLive'
44 '@id': 'pt:latencyMode'
47 Infohash: 'pt:Infohash',
49 originallyPublishedAt: 'sc:datePublished',
67 '@type': 'sc:Boolean',
68 '@id': 'pt:commentsEnabled'
71 '@type': 'sc:Boolean',
72 '@id': 'pt:downloadEnabled'
75 '@type': 'sc:Boolean',
76 '@id': 'pt:waitTranscoding'
100 Playlist: buildContext({
101 Playlist: 'pt:Playlist',
102 PlaylistElement: 'pt:PlaylistElement',
104 '@type': 'sc:Number',
108 '@type': 'sc:Number',
109 '@id': 'pt:startTimestamp'
112 '@type': 'sc:Number',
113 '@id': 'pt:stopTimestamp'
115 uuid: 'sc:identifier'
118 CacheFile: buildContext({
119 expires: 'sc:expires',
120 CacheFile: 'pt:CacheFile'
124 Hashtag: 'as:Hashtag'
127 Actor: buildContext({
129 '@id': 'pt:playlists',
137 // TODO: remove in a few versions, introduced in 4.2
141 WatchAction: buildContext({
142 WatchAction: 'sc:WatchAction',
144 '@type': 'sc:Number',
145 '@id': 'pt:startTimestamp'
148 '@type': 'sc:Number',
149 '@id': 'pt:stopTimestamp'
152 '@type': 'sc:Number',
153 '@id': 'pt:stopTimestamp'
155 uuid: 'sc:identifier'
158 Collection: buildContext(),
159 Follow: buildContext(),
160 Reject: buildContext(),
161 Accept: buildContext(),
162 View: buildContext(),
163 Announce: buildContext(),
164 Comment: buildContext(),
165 Delete: buildContext(),
169 async function getContextData (type: ContextType) {
170 const contextData = await Hooks.wrapObject(
172 'filter:activity-pub.activity.context.build.result'
175 return { '@context': contextData }
178 function buildContext (contextValue?: ContextValue) {
179 const baseContext = [
180 'https://www.w3.org/ns/activitystreams',
181 'https://w3id.org/security/v1',
183 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
187 if (!contextValue) return baseContext
193 pt: 'https://joinpeertube.org/ns#',
194 sc: 'http://schema.org/',