]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/context.ts
Fix search index tests
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / context.ts
CommitLineData
7e98a7df 1import { ContextType } from '@shared/models'
598edb8a 2
a219c910
C
3function activityPubContextify <T> (data: T, type: ContextType) {
4 return { ...getContextData(type), ...data }
5}
6
7// ---------------------------------------------------------------------------
8
9export {
10 getContextData,
11 activityPubContextify
12}
13
14// ---------------------------------------------------------------------------
15
16type ContextValue = { [ id: string ]: (string | { '@type': string, '@id': string }) }
17
b2111066 18const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string })[] } = {
a219c910
C
19 Video: buildContext({
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
28 // TODO: remove in a few versions, introduced in 4.2
29 icons: 'as:icon',
30
31 isLiveBroadcast: 'sc:isLiveBroadcast',
32 liveSaveReplay: {
33 '@type': 'sc:Boolean',
34 '@id': 'pt:liveSaveReplay'
35 },
36 permanentLive: {
37 '@type': 'sc:Boolean',
38 '@id': 'pt:permanentLive'
39 },
40 latencyMode: {
41 '@type': 'sc:Number',
42 '@id': 'pt:latencyMode'
43 },
44
45 Infohash: 'pt:Infohash',
46
47 originallyPublishedAt: 'sc:datePublished',
48 views: {
49 '@type': 'sc:Number',
50 '@id': 'pt:views'
51 },
52 state: {
53 '@type': 'sc:Number',
54 '@id': 'pt:state'
55 },
56 size: {
57 '@type': 'sc:Number',
58 '@id': 'pt:size'
59 },
60 fps: {
61 '@type': 'sc:Number',
62 '@id': 'pt:fps'
63 },
64 commentsEnabled: {
65 '@type': 'sc:Boolean',
66 '@id': 'pt:commentsEnabled'
67 },
68 downloadEnabled: {
69 '@type': 'sc:Boolean',
70 '@id': 'pt:downloadEnabled'
71 },
72 waitTranscoding: {
73 '@type': 'sc:Boolean',
74 '@id': 'pt:waitTranscoding'
75 },
76 support: {
77 '@type': 'sc:Text',
78 '@id': 'pt:support'
79 },
80 likes: {
81 '@id': 'as:likes',
82 '@type': '@id'
83 },
84 dislikes: {
85 '@id': 'as:dislikes',
86 '@type': '@id'
87 },
88 shares: {
89 '@id': 'as:shares',
90 '@type': '@id'
91 },
92 comments: {
93 '@id': 'as:comments',
94 '@type': '@id'
084a2cd0 95 }
a219c910 96 }),
598edb8a 97
a219c910
C
98 Playlist: buildContext({
99 Playlist: 'pt:Playlist',
100 PlaylistElement: 'pt:PlaylistElement',
101 position: {
102 '@type': 'sc:Number',
103 '@id': 'pt:position'
104 },
105 startTimestamp: {
106 '@type': 'sc:Number',
107 '@id': 'pt:startTimestamp'
108 },
109 stopTimestamp: {
110 '@type': 'sc:Number',
111 '@id': 'pt:stopTimestamp'
b2111066
C
112 },
113 uuid: 'sc:identifier'
a219c910
C
114 }),
115
116 CacheFile: buildContext({
117 expires: 'sc:expires',
118 CacheFile: 'pt:CacheFile'
119 }),
084a2cd0 120
a219c910
C
121 Flag: buildContext({
122 Hashtag: 'as:Hashtag'
123 }),
124
125 Actor: buildContext({
126 playlists: {
127 '@id': 'pt:playlists',
128 '@type': '@id'
084a2cd0 129 }
a219c910 130 }),
084a2cd0 131
b2111066
C
132 WatchAction: buildContext({
133 WatchAction: 'sc:WatchAction',
134 startTimestamp: {
135 '@type': 'sc:Number',
136 '@id': 'pt:startTimestamp'
137 },
138 stopTimestamp: {
139 '@type': 'sc:Number',
140 '@id': 'pt:stopTimestamp'
141 },
142 watchSection: {
143 '@type': 'sc:Number',
144 '@id': 'pt:stopTimestamp'
145 },
146 uuid: 'sc:identifier'
147 }),
148
149 Collection: buildContext(),
a219c910
C
150 Follow: buildContext(),
151 Reject: buildContext(),
152 Accept: buildContext(),
153 View: buildContext(),
154 Announce: buildContext(),
155 Comment: buildContext(),
156 Delete: buildContext(),
157 Rate: buildContext()
158}
598edb8a 159
a219c910 160function getContextData (type: ContextType) {
084a2cd0 161 return {
a219c910 162 '@context': contextStore[type]
084a2cd0
C
163 }
164}
165
a219c910
C
166function buildContext (contextValue?: ContextValue) {
167 const baseContext = [
168 'https://www.w3.org/ns/activitystreams',
169 'https://w3id.org/security/v1',
170 {
171 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
172 }
173 ]
e4f97bab 174
a219c910
C
175 if (!contextValue) return baseContext
176
177 return [
178 ...baseContext,
179
180 {
181 pt: 'https://joinpeertube.org/ns#',
182 sc: 'http://schema.org#',
183
184 ...contextValue
185 }
186 ]
e4f97bab 187}