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',
27 identifier: 'sc:identifier',
29 // TODO: remove in a few versions, introduced in 4.2
32 isLiveBroadcast: 'sc:isLiveBroadcast',
34 '@type': 'sc:Boolean',
35 '@id': 'pt:liveSaveReplay'
38 '@type': 'sc:Boolean',
39 '@id': 'pt:permanentLive'
43 '@id': 'pt:latencyMode'
46 Infohash: 'pt:Infohash',
48 originallyPublishedAt: 'sc:datePublished',
66 '@type': 'sc:Boolean',
67 '@id': 'pt:commentsEnabled'
70 '@type': 'sc:Boolean',
71 '@id': 'pt:downloadEnabled'
74 '@type': 'sc:Boolean',
75 '@id': 'pt:waitTranscoding'
99 Playlist: buildContext({
100 Playlist: 'pt:Playlist',
101 PlaylistElement: 'pt:PlaylistElement',
103 '@type': 'sc:Number',
107 '@type': 'sc:Number',
108 '@id': 'pt:startTimestamp'
111 '@type': 'sc:Number',
112 '@id': 'pt:stopTimestamp'
114 uuid: 'sc:identifier'
117 CacheFile: buildContext({
118 expires: 'sc:expires',
119 CacheFile: 'pt:CacheFile'
123 Hashtag: 'as:Hashtag'
126 Actor: buildContext({
128 '@id': 'pt:playlists',
136 // TODO: remove in a few versions, introduced in 4.2
140 WatchAction: buildContext({
141 WatchAction: 'sc:WatchAction',
143 '@type': 'sc:Number',
144 '@id': 'pt:startTimestamp'
147 '@type': 'sc:Number',
148 '@id': 'pt:stopTimestamp'
151 '@type': 'sc:Number',
152 '@id': 'pt:stopTimestamp'
154 uuid: 'sc:identifier'
157 Collection: buildContext(),
158 Follow: buildContext(),
159 Reject: buildContext(),
160 Accept: buildContext(),
161 View: buildContext(),
162 Announce: buildContext(),
163 Comment: buildContext(),
164 Delete: buildContext(),
168 function getContextData (type: ContextType) {
170 '@context': contextStore[type]
174 function buildContext (contextValue?: ContextValue) {
175 const baseContext = [
176 'https://www.w3.org/ns/activitystreams',
177 'https://w3id.org/security/v1',
179 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
183 if (!contextValue) return baseContext
189 pt: 'https://joinpeertube.org/ns#',
190 sc: 'http://schema.org/',