]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/context.ts
Remove activitypub helper
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / context.ts
CommitLineData
7e98a7df 1import { ContextType } from '@shared/models'
598edb8a 2
084a2cd0
C
3function 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 ]
598edb8a 11
084a2cd0
C
12 if (type !== 'View' && type !== 'Announce') {
13 const additional = {
598edb8a 14 pt: 'https://joinpeertube.org/ns#',
084a2cd0
C
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
d0800f76 33 // TODO: remove in a few versions, introduced in 4.2
34 icons: 'as:icon',
35
bb4ba6d9
C
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 },
f443a746
C
45 latencyMode: {
46 '@type': 'sc:Number',
47 '@id': 'pt:latencyMode'
48 },
bb4ba6d9 49
084a2cd0 50 Infohash: 'pt:Infohash',
9934b6f3
C
51 Playlist: 'pt:Playlist',
52 PlaylistElement: 'pt:PlaylistElement',
53
084a2cd0
C
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)
598edb8a
C
123 }
124
084a2cd0
C
125 return {
126 '@context': context
127 }
128}
129
130function activityPubContextify <T> (data: T, type: ContextType = 'All') {
131 return Object.assign({}, data, getContextData(type))
e4f97bab
C
132}
133
e4f97bab 134export {
7e98a7df
C
135 getContextData,
136 activityPubContextify
e4f97bab 137}