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