aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/activitypub.ts179
1 files changed, 93 insertions, 86 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts
index 22f8550ca..326785b68 100644
--- a/server/helpers/activitypub.ts
+++ b/server/helpers/activitypub.ts
@@ -8,93 +8,100 @@ import { pageToStartAndCount } from './core-utils'
8import { URL } from 'url' 8import { URL } from 'url'
9import { MActor, MVideoAccountLight } from '../typings/models' 9import { MActor, MVideoAccountLight } from '../typings/models'
10 10
11function activityPubContextify <T> (data: T) { 11export type ContextType = 'All' | 'View' | 'Announce'
12 return Object.assign(data, { 12
13function activityPubContextify <T> (data: T, type: ContextType = 'All') {
14 const base = {
15 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017'
16 }
17
18 if (type === 'All') {
19 Object.assign(base, {
20 pt: 'https://joinpeertube.org/ns#',
21 sc: 'http://schema.org#',
22 Hashtag: 'as:Hashtag',
23 uuid: 'sc:identifier',
24 category: 'sc:category',
25 licence: 'sc:license',
26 subtitleLanguage: 'sc:subtitleLanguage',
27 sensitive: 'as:sensitive',
28 language: 'sc:inLanguage',
29 expires: 'sc:expires',
30 CacheFile: 'pt:CacheFile',
31 Infohash: 'pt:Infohash',
32 originallyPublishedAt: 'sc:datePublished',
33 views: {
34 '@type': 'sc:Number',
35 '@id': 'pt:views'
36 },
37 state: {
38 '@type': 'sc:Number',
39 '@id': 'pt:state'
40 },
41 size: {
42 '@type': 'sc:Number',
43 '@id': 'pt:size'
44 },
45 fps: {
46 '@type': 'sc:Number',
47 '@id': 'pt:fps'
48 },
49 startTimestamp: {
50 '@type': 'sc:Number',
51 '@id': 'pt:startTimestamp'
52 },
53 stopTimestamp: {
54 '@type': 'sc:Number',
55 '@id': 'pt:stopTimestamp'
56 },
57 position: {
58 '@type': 'sc:Number',
59 '@id': 'pt:position'
60 },
61 commentsEnabled: {
62 '@type': 'sc:Boolean',
63 '@id': 'pt:commentsEnabled'
64 },
65 downloadEnabled: {
66 '@type': 'sc:Boolean',
67 '@id': 'pt:downloadEnabled'
68 },
69 waitTranscoding: {
70 '@type': 'sc:Boolean',
71 '@id': 'pt:waitTranscoding'
72 },
73 support: {
74 '@type': 'sc:Text',
75 '@id': 'pt:support'
76 },
77 likes: {
78 '@id': 'as:likes',
79 '@type': '@id'
80 },
81 dislikes: {
82 '@id': 'as:dislikes',
83 '@type': '@id'
84 },
85 playlists: {
86 '@id': 'pt:playlists',
87 '@type': '@id'
88 },
89 shares: {
90 '@id': 'as:shares',
91 '@type': '@id'
92 },
93 comments: {
94 '@id': 'as:comments',
95 '@type': '@id'
96 }
97 })
98 }
99
100 return Object.assign({}, data, {
13 '@context': [ 101 '@context': [
14 'https://www.w3.org/ns/activitystreams', 102 'https://www.w3.org/ns/activitystreams',
15 'https://w3id.org/security/v1', 103 'https://w3id.org/security/v1',
16 { 104 base
17 RsaSignature2017: 'https://w3id.org/security#RsaSignature2017',
18 pt: 'https://joinpeertube.org/ns#',
19 sc: 'http://schema.org#',
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 expires: 'sc:expires',
28 CacheFile: 'pt:CacheFile',
29 Infohash: 'pt:Infohash',
30 originallyPublishedAt: 'sc:datePublished',
31 views: {
32 '@type': 'sc:Number',
33 '@id': 'pt:views'
34 },
35 state: {
36 '@type': 'sc:Number',
37 '@id': 'pt:state'
38 },
39 size: {
40 '@type': 'sc:Number',
41 '@id': 'pt:size'
42 },
43 fps: {
44 '@type': 'sc:Number',
45 '@id': 'pt:fps'
46 },
47 startTimestamp: {
48 '@type': 'sc:Number',
49 '@id': 'pt:startTimestamp'
50 },
51 stopTimestamp: {
52 '@type': 'sc:Number',
53 '@id': 'pt:stopTimestamp'
54 },
55 position: {
56 '@type': 'sc:Number',
57 '@id': 'pt:position'
58 },
59 commentsEnabled: {
60 '@type': 'sc:Boolean',
61 '@id': 'pt:commentsEnabled'
62 },
63 downloadEnabled: {
64 '@type': 'sc:Boolean',
65 '@id': 'pt:downloadEnabled'
66 },
67 waitTranscoding: {
68 '@type': 'sc:Boolean',
69 '@id': 'pt:waitTranscoding'
70 },
71 support: {
72 '@type': 'sc:Text',
73 '@id': 'pt:support'
74 }
75 },
76 {
77 likes: {
78 '@id': 'as:likes',
79 '@type': '@id'
80 },
81 dislikes: {
82 '@id': 'as:dislikes',
83 '@type': '@id'
84 },
85 playlists: {
86 '@id': 'pt:playlists',
87 '@type': '@id'
88 },
89 shares: {
90 '@id': 'as:shares',
91 '@type': '@id'
92 },
93 comments: {
94 '@id': 'as:comments',
95 '@type': '@id'
96 }
97 }
98 ] 105 ]
99 }) 106 })
100} 107}
@@ -148,8 +155,8 @@ async function activityPubCollectionPagination (
148 155
149} 156}
150 157
151function buildSignedActivity (byActor: MActor, data: Object) { 158function buildSignedActivity (byActor: MActor, data: Object, contextType?: ContextType) {
152 const activity = activityPubContextify(data) 159 const activity = activityPubContextify(data, contextType)
153 160
154 return signJsonLDObject(byActor, activity) as Promise<Activity> 161 return signJsonLDObject(byActor, activity) as Promise<Activity>
155} 162}