aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/context.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/context.ts')
-rw-r--r--server/lib/activitypub/context.ts212
1 files changed, 0 insertions, 212 deletions
diff --git a/server/lib/activitypub/context.ts b/server/lib/activitypub/context.ts
deleted file mode 100644
index 87eb498a3..000000000
--- a/server/lib/activitypub/context.ts
+++ /dev/null
@@ -1,212 +0,0 @@
1import { ContextType } from '@shared/models'
2import { Hooks } from '../plugins/hooks'
3
4async function activityPubContextify <T> (data: T, type: ContextType) {
5 return { ...await getContextData(type), ...data }
6}
7
8// ---------------------------------------------------------------------------
9
10export {
11 getContextData,
12 activityPubContextify
13}
14
15// ---------------------------------------------------------------------------
16
17type ContextValue = { [ id: string ]: (string | { '@type': string, '@id': string }) }
18
19const contextStore: { [ id in ContextType ]: (string | { [ id: string ]: string })[] } = {
20 Video: buildContext({
21 Hashtag: 'as:Hashtag',
22 uuid: 'sc:identifier',
23 category: 'sc:category',
24 licence: 'sc:license',
25 subtitleLanguage: 'sc:subtitleLanguage',
26 sensitive: 'as:sensitive',
27 language: 'sc:inLanguage',
28 identifier: 'sc:identifier',
29
30 isLiveBroadcast: 'sc:isLiveBroadcast',
31 liveSaveReplay: {
32 '@type': 'sc:Boolean',
33 '@id': 'pt:liveSaveReplay'
34 },
35 permanentLive: {
36 '@type': 'sc:Boolean',
37 '@id': 'pt:permanentLive'
38 },
39 latencyMode: {
40 '@type': 'sc:Number',
41 '@id': 'pt:latencyMode'
42 },
43
44 Infohash: 'pt:Infohash',
45
46 tileWidth: {
47 '@type': 'sc:Number',
48 '@id': 'pt:tileWidth'
49 },
50 tileHeight: {
51 '@type': 'sc:Number',
52 '@id': 'pt:tileHeight'
53 },
54 tileDuration: {
55 '@type': 'sc:Number',
56 '@id': 'pt:tileDuration'
57 },
58
59 originallyPublishedAt: 'sc:datePublished',
60
61 uploadDate: 'sc:uploadDate',
62
63 views: {
64 '@type': 'sc:Number',
65 '@id': 'pt:views'
66 },
67 state: {
68 '@type': 'sc:Number',
69 '@id': 'pt:state'
70 },
71 size: {
72 '@type': 'sc:Number',
73 '@id': 'pt:size'
74 },
75 fps: {
76 '@type': 'sc:Number',
77 '@id': 'pt:fps'
78 },
79 commentsEnabled: {
80 '@type': 'sc:Boolean',
81 '@id': 'pt:commentsEnabled'
82 },
83 downloadEnabled: {
84 '@type': 'sc:Boolean',
85 '@id': 'pt:downloadEnabled'
86 },
87 waitTranscoding: {
88 '@type': 'sc:Boolean',
89 '@id': 'pt:waitTranscoding'
90 },
91 support: {
92 '@type': 'sc:Text',
93 '@id': 'pt:support'
94 },
95 likes: {
96 '@id': 'as:likes',
97 '@type': '@id'
98 },
99 dislikes: {
100 '@id': 'as:dislikes',
101 '@type': '@id'
102 },
103 shares: {
104 '@id': 'as:shares',
105 '@type': '@id'
106 },
107 comments: {
108 '@id': 'as:comments',
109 '@type': '@id'
110 }
111 }),
112
113 Playlist: buildContext({
114 Playlist: 'pt:Playlist',
115 PlaylistElement: 'pt:PlaylistElement',
116 position: {
117 '@type': 'sc:Number',
118 '@id': 'pt:position'
119 },
120 startTimestamp: {
121 '@type': 'sc:Number',
122 '@id': 'pt:startTimestamp'
123 },
124 stopTimestamp: {
125 '@type': 'sc:Number',
126 '@id': 'pt:stopTimestamp'
127 },
128 uuid: 'sc:identifier'
129 }),
130
131 CacheFile: buildContext({
132 expires: 'sc:expires',
133 CacheFile: 'pt:CacheFile'
134 }),
135
136 Flag: buildContext({
137 Hashtag: 'as:Hashtag'
138 }),
139
140 Actor: buildContext({
141 playlists: {
142 '@id': 'pt:playlists',
143 '@type': '@id'
144 },
145 support: {
146 '@type': 'sc:Text',
147 '@id': 'pt:support'
148 },
149
150 // TODO: remove in a few versions, introduced in 4.2
151 icons: 'as:icon'
152 }),
153
154 WatchAction: buildContext({
155 WatchAction: 'sc:WatchAction',
156 startTimestamp: {
157 '@type': 'sc:Number',
158 '@id': 'pt:startTimestamp'
159 },
160 stopTimestamp: {
161 '@type': 'sc:Number',
162 '@id': 'pt:stopTimestamp'
163 },
164 watchSection: {
165 '@type': 'sc:Number',
166 '@id': 'pt:stopTimestamp'
167 },
168 uuid: 'sc:identifier'
169 }),
170
171 Collection: buildContext(),
172 Follow: buildContext(),
173 Reject: buildContext(),
174 Accept: buildContext(),
175 View: buildContext(),
176 Announce: buildContext(),
177 Comment: buildContext(),
178 Delete: buildContext(),
179 Rate: buildContext()
180}
181
182async function getContextData (type: ContextType) {
183 const contextData = await Hooks.wrapObject(
184 contextStore[type],
185 'filter:activity-pub.activity.context.build.result'
186 )
187
188 return { '@context': contextData }
189}
190
191function buildContext (contextValue?: ContextValue) {
192 const baseContext = [
193 'https://www.w3.org/ns/activitystreams',
194 'https://w3id.org/security/v1',
195 {
196 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
197 }
198 ]
199
200 if (!contextValue) return baseContext
201
202 return [
203 ...baseContext,
204
205 {
206 pt: 'https://joinpeertube.org/ns#',
207 sc: 'http://schema.org/',
208
209 ...contextValue
210 }
211 ]
212}