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 = {
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'
115 CacheFile: buildContext({
116 expires: 'sc:expires',
117 CacheFile: 'pt:CacheFile'
121 Hashtag: 'as:Hashtag'
124 Actor: buildContext({
126 '@id': 'pt:playlists',
131 Follow: buildContext(),
132 Reject: buildContext(),
133 Accept: buildContext(),
134 View: buildContext(),
135 Announce: buildContext(),
136 Comment: buildContext(),
137 Delete: buildContext(),
141 function getContextData (type: ContextType) {
143 '@context': contextStore[type]
147 function buildContext (contextValue?: ContextValue) {
148 const baseContext = [
149 'https://www.w3.org/ns/activitystreams',
150 'https://w3id.org/security/v1',
152 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
156 if (!contextValue) return baseContext
162 pt: 'https://joinpeertube.org/ns#',
163 sc: 'http://schema.org#',