1 import { ContextType } from '@shared/models'
3 function activityPubContextify <T> (data: T, type: ContextType) {
4 return { ...getContextData(type), ...data }
7 // ---------------------------------------------------------------------------
14 // ---------------------------------------------------------------------------
16 type ContextValue = { [ id: string ]: (string | { '@type': string, '@id': string }) }
18 const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string })[] } = {
20 Hashtag: 'as:Hashtag',
21 uuid: 'sc:identifier',
22 category: 'sc:category',
23 licence: 'sc:license',
24 subtitleLanguage: 'sc:subtitleLanguage',
25 sensitive: 'as:sensitive',
26 language: 'sc:inLanguage',
28 // TODO: remove in a few versions, introduced in 4.2
31 isLiveBroadcast: 'sc:isLiveBroadcast',
33 '@type': 'sc:Boolean',
34 '@id': 'pt:liveSaveReplay'
37 '@type': 'sc:Boolean',
38 '@id': 'pt:permanentLive'
42 '@id': 'pt:latencyMode'
45 Infohash: 'pt:Infohash',
47 originallyPublishedAt: 'sc:datePublished',
65 '@type': 'sc:Boolean',
66 '@id': 'pt:commentsEnabled'
69 '@type': 'sc:Boolean',
70 '@id': 'pt:downloadEnabled'
73 '@type': 'sc:Boolean',
74 '@id': 'pt:waitTranscoding'
98 Playlist: buildContext({
99 Playlist: 'pt:Playlist',
100 PlaylistElement: 'pt:PlaylistElement',
102 '@type': 'sc:Number',
106 '@type': 'sc:Number',
107 '@id': 'pt:startTimestamp'
110 '@type': 'sc:Number',
111 '@id': 'pt:stopTimestamp'
113 uuid: 'sc:identifier'
116 CacheFile: buildContext({
117 expires: 'sc:expires',
118 CacheFile: 'pt:CacheFile'
122 Hashtag: 'as:Hashtag'
125 Actor: buildContext({
127 '@id': 'pt:playlists',
132 WatchAction: buildContext({
133 WatchAction: 'sc:WatchAction',
135 '@type': 'sc:Number',
136 '@id': 'pt:startTimestamp'
139 '@type': 'sc:Number',
140 '@id': 'pt:stopTimestamp'
143 '@type': 'sc:Number',
144 '@id': 'pt:stopTimestamp'
146 uuid: 'sc:identifier'
149 Collection: buildContext(),
150 Follow: buildContext(),
151 Reject: buildContext(),
152 Accept: buildContext(),
153 View: buildContext(),
154 Announce: buildContext(),
155 Comment: buildContext(),
156 Delete: buildContext(),
160 function getContextData (type: ContextType) {
162 '@context': contextStore[type]
166 function buildContext (contextValue?: ContextValue) {
167 const baseContext = [
168 'https://www.w3.org/ns/activitystreams',
169 'https://w3id.org/security/v1',
171 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
175 if (!contextValue) return baseContext
181 pt: 'https://joinpeertube.org/ns#',
182 sc: 'http://schema.org/',