diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-23 14:24:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-23 14:24:50 +0100 |
commit | 7e98a7df7d04e19ba67163a86c7b876d78d76839 (patch) | |
tree | 080c9bf63d2b00b43dca94e3c67cdc2a768308fc /server/lib/activitypub/context.ts | |
parent | 5302f77d095c2188859ee463128aa59eec20ea88 (diff) | |
download | PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.tar.gz PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.tar.zst PeerTube-7e98a7df7d04e19ba67163a86c7b876d78d76839.zip |
Remove activitypub helper
Put functions in lib/activitypub instead
Diffstat (limited to 'server/lib/activitypub/context.ts')
-rw-r--r-- | server/lib/activitypub/context.ts | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/server/lib/activitypub/context.ts b/server/lib/activitypub/context.ts new file mode 100644 index 000000000..71f08da80 --- /dev/null +++ b/server/lib/activitypub/context.ts | |||
@@ -0,0 +1,137 @@ | |||
1 | import { ContextType } from '@shared/models' | ||
2 | |||
3 | function getContextData (type: ContextType) { | ||
4 | const context: any[] = [ | ||
5 | 'https://www.w3.org/ns/activitystreams', | ||
6 | 'https://w3id.org/security/v1', | ||
7 | { | ||
8 | RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' | ||
9 | } | ||
10 | ] | ||
11 | |||
12 | if (type !== 'View' && type !== 'Announce') { | ||
13 | const additional = { | ||
14 | pt: 'https://joinpeertube.org/ns#', | ||
15 | sc: 'http://schema.org#' | ||
16 | } | ||
17 | |||
18 | if (type === 'CacheFile') { | ||
19 | Object.assign(additional, { | ||
20 | expires: 'sc:expires', | ||
21 | CacheFile: 'pt:CacheFile' | ||
22 | }) | ||
23 | } else { | ||
24 | Object.assign(additional, { | ||
25 | Hashtag: 'as:Hashtag', | ||
26 | uuid: 'sc:identifier', | ||
27 | category: 'sc:category', | ||
28 | licence: 'sc:license', | ||
29 | subtitleLanguage: 'sc:subtitleLanguage', | ||
30 | sensitive: 'as:sensitive', | ||
31 | language: 'sc:inLanguage', | ||
32 | |||
33 | // TODO: remove in a few versions, introduced in 4.2 | ||
34 | icons: 'as:icon', | ||
35 | |||
36 | isLiveBroadcast: 'sc:isLiveBroadcast', | ||
37 | liveSaveReplay: { | ||
38 | '@type': 'sc:Boolean', | ||
39 | '@id': 'pt:liveSaveReplay' | ||
40 | }, | ||
41 | permanentLive: { | ||
42 | '@type': 'sc:Boolean', | ||
43 | '@id': 'pt:permanentLive' | ||
44 | }, | ||
45 | latencyMode: { | ||
46 | '@type': 'sc:Number', | ||
47 | '@id': 'pt:latencyMode' | ||
48 | }, | ||
49 | |||
50 | Infohash: 'pt:Infohash', | ||
51 | Playlist: 'pt:Playlist', | ||
52 | PlaylistElement: 'pt:PlaylistElement', | ||
53 | |||
54 | originallyPublishedAt: 'sc:datePublished', | ||
55 | views: { | ||
56 | '@type': 'sc:Number', | ||
57 | '@id': 'pt:views' | ||
58 | }, | ||
59 | state: { | ||
60 | '@type': 'sc:Number', | ||
61 | '@id': 'pt:state' | ||
62 | }, | ||
63 | size: { | ||
64 | '@type': 'sc:Number', | ||
65 | '@id': 'pt:size' | ||
66 | }, | ||
67 | fps: { | ||
68 | '@type': 'sc:Number', | ||
69 | '@id': 'pt:fps' | ||
70 | }, | ||
71 | startTimestamp: { | ||
72 | '@type': 'sc:Number', | ||
73 | '@id': 'pt:startTimestamp' | ||
74 | }, | ||
75 | stopTimestamp: { | ||
76 | '@type': 'sc:Number', | ||
77 | '@id': 'pt:stopTimestamp' | ||
78 | }, | ||
79 | position: { | ||
80 | '@type': 'sc:Number', | ||
81 | '@id': 'pt:position' | ||
82 | }, | ||
83 | commentsEnabled: { | ||
84 | '@type': 'sc:Boolean', | ||
85 | '@id': 'pt:commentsEnabled' | ||
86 | }, | ||
87 | downloadEnabled: { | ||
88 | '@type': 'sc:Boolean', | ||
89 | '@id': 'pt:downloadEnabled' | ||
90 | }, | ||
91 | waitTranscoding: { | ||
92 | '@type': 'sc:Boolean', | ||
93 | '@id': 'pt:waitTranscoding' | ||
94 | }, | ||
95 | support: { | ||
96 | '@type': 'sc:Text', | ||
97 | '@id': 'pt:support' | ||
98 | }, | ||
99 | likes: { | ||
100 | '@id': 'as:likes', | ||
101 | '@type': '@id' | ||
102 | }, | ||
103 | dislikes: { | ||
104 | '@id': 'as:dislikes', | ||
105 | '@type': '@id' | ||
106 | }, | ||
107 | playlists: { | ||
108 | '@id': 'pt:playlists', | ||
109 | '@type': '@id' | ||
110 | }, | ||
111 | shares: { | ||
112 | '@id': 'as:shares', | ||
113 | '@type': '@id' | ||
114 | }, | ||
115 | comments: { | ||
116 | '@id': 'as:comments', | ||
117 | '@type': '@id' | ||
118 | } | ||
119 | }) | ||
120 | } | ||
121 | |||
122 | context.push(additional) | ||
123 | } | ||
124 | |||
125 | return { | ||
126 | '@context': context | ||
127 | } | ||
128 | } | ||
129 | |||
130 | function activityPubContextify <T> (data: T, type: ContextType = 'All') { | ||
131 | return Object.assign({}, data, getContextData(type)) | ||
132 | } | ||
133 | |||
134 | export { | ||
135 | getContextData, | ||
136 | activityPubContextify | ||
137 | } | ||