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',
133 WatchAction: buildContext({
134 WatchAction: 'sc:WatchAction',
136 '@type': 'sc:Number',
137 '@id': 'pt:startTimestamp'
140 '@type': 'sc:Number',
141 '@id': 'pt:stopTimestamp'
144 '@type': 'sc:Number',
145 '@id': 'pt:stopTimestamp'
147 uuid: 'sc:identifier'
150 Collection: buildContext(),
151 Follow: buildContext(),
152 Reject: buildContext(),
153 Accept: buildContext(),
154 View: buildContext(),
155 Announce: buildContext(),
156 Comment: buildContext(),
157 Delete: buildContext(),
161 function getContextData (type: ContextType) {
163 '@context': contextStore[type]
167 function buildContext (contextValue?: ContextValue) {
168 const baseContext = [
169 'https://www.w3.org/ns/activitystreams',
170 'https://w3id.org/security/v1',
172 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
176 if (!contextValue) return baseContext
182 pt: 'https://joinpeertube.org/ns#',
183 sc: 'http://schema.org/',