diff options
author | Chocobozzz <me@florianbigard.com> | 2020-02-04 16:34:46 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-02-04 16:34:46 +0100 |
commit | 084a2cd0f6274afac0fbcd714e627273da1df25e (patch) | |
tree | ee77411b98b8e2ef671b24a91dbd4b6dcdcd9d37 /server | |
parent | 2c8776fc316da9719e5ebc55dfabdcac9e197ac4 (diff) | |
download | PeerTube-084a2cd0f6274afac0fbcd714e627273da1df25e.tar.gz PeerTube-084a2cd0f6274afac0fbcd714e627273da1df25e.tar.zst PeerTube-084a2cd0f6274afac0fbcd714e627273da1df25e.zip |
Optimize context for CacheFile
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/activitypub/client.ts | 4 | ||||
-rw-r--r-- | server/helpers/activitypub.ts | 197 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-create.ts | 5 | ||||
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 2 |
4 files changed, 113 insertions, 95 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 395cfa0d5..84828e7e0 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -335,10 +335,10 @@ async function videoRedundancyController (req: express.Request, res: express.Res | |||
335 | 335 | ||
336 | if (req.path.endsWith('/activity')) { | 336 | if (req.path.endsWith('/activity')) { |
337 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) | 337 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) |
338 | return activityPubResponse(activityPubContextify(data), res) | 338 | return activityPubResponse(activityPubContextify(data, 'CacheFile'), res) |
339 | } | 339 | } |
340 | 340 | ||
341 | return activityPubResponse(activityPubContextify(object), res) | 341 | return activityPubResponse(activityPubContextify(object, 'CacheFile'), res) |
342 | } | 342 | } |
343 | 343 | ||
344 | async function videoPlaylistController (req: express.Request, res: express.Response) { | 344 | async function videoPlaylistController (req: express.Request, res: express.Response) { |
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index 326785b68..2d49e6869 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -8,102 +8,117 @@ import { pageToStartAndCount } from './core-utils' | |||
8 | import { URL } from 'url' | 8 | import { URL } from 'url' |
9 | import { MActor, MVideoAccountLight } from '../typings/models' | 9 | import { MActor, MVideoAccountLight } from '../typings/models' |
10 | 10 | ||
11 | export type ContextType = 'All' | 'View' | 'Announce' | 11 | export type ContextType = 'All' | 'View' | 'Announce' | 'CacheFile' |
12 | |||
13 | function getContextData (type: ContextType) { | ||
14 | const context: any[] = [ | ||
15 | 'https://www.w3.org/ns/activitystreams', | ||
16 | 'https://w3id.org/security/v1', | ||
17 | { | ||
18 | RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' | ||
19 | } | ||
20 | ] | ||
12 | 21 | ||
13 | function activityPubContextify <T> (data: T, type: ContextType = 'All') { | 22 | if (type !== 'View' && type !== 'Announce') { |
14 | const base = { | 23 | const additional = { |
15 | RsaSignature2017: 'https://w3id.org/security#RsaSignature2017' | 24 | pt: 'https://joinpeertube.org/ns#', |
25 | sc: 'http://schema.org#' | ||
26 | } | ||
27 | |||
28 | if (type === 'CacheFile') { | ||
29 | Object.assign(additional, { | ||
30 | expires: 'sc:expires', | ||
31 | CacheFile: 'pt:CacheFile' | ||
32 | }) | ||
33 | } else { | ||
34 | Object.assign(additional, { | ||
35 | Hashtag: 'as:Hashtag', | ||
36 | uuid: 'sc:identifier', | ||
37 | category: 'sc:category', | ||
38 | licence: 'sc:license', | ||
39 | subtitleLanguage: 'sc:subtitleLanguage', | ||
40 | sensitive: 'as:sensitive', | ||
41 | language: 'sc:inLanguage', | ||
42 | |||
43 | Infohash: 'pt:Infohash', | ||
44 | originallyPublishedAt: 'sc:datePublished', | ||
45 | views: { | ||
46 | '@type': 'sc:Number', | ||
47 | '@id': 'pt:views' | ||
48 | }, | ||
49 | state: { | ||
50 | '@type': 'sc:Number', | ||
51 | '@id': 'pt:state' | ||
52 | }, | ||
53 | size: { | ||
54 | '@type': 'sc:Number', | ||
55 | '@id': 'pt:size' | ||
56 | }, | ||
57 | fps: { | ||
58 | '@type': 'sc:Number', | ||
59 | '@id': 'pt:fps' | ||
60 | }, | ||
61 | startTimestamp: { | ||
62 | '@type': 'sc:Number', | ||
63 | '@id': 'pt:startTimestamp' | ||
64 | }, | ||
65 | stopTimestamp: { | ||
66 | '@type': 'sc:Number', | ||
67 | '@id': 'pt:stopTimestamp' | ||
68 | }, | ||
69 | position: { | ||
70 | '@type': 'sc:Number', | ||
71 | '@id': 'pt:position' | ||
72 | }, | ||
73 | commentsEnabled: { | ||
74 | '@type': 'sc:Boolean', | ||
75 | '@id': 'pt:commentsEnabled' | ||
76 | }, | ||
77 | downloadEnabled: { | ||
78 | '@type': 'sc:Boolean', | ||
79 | '@id': 'pt:downloadEnabled' | ||
80 | }, | ||
81 | waitTranscoding: { | ||
82 | '@type': 'sc:Boolean', | ||
83 | '@id': 'pt:waitTranscoding' | ||
84 | }, | ||
85 | support: { | ||
86 | '@type': 'sc:Text', | ||
87 | '@id': 'pt:support' | ||
88 | }, | ||
89 | likes: { | ||
90 | '@id': 'as:likes', | ||
91 | '@type': '@id' | ||
92 | }, | ||
93 | dislikes: { | ||
94 | '@id': 'as:dislikes', | ||
95 | '@type': '@id' | ||
96 | }, | ||
97 | playlists: { | ||
98 | '@id': 'pt:playlists', | ||
99 | '@type': '@id' | ||
100 | }, | ||
101 | shares: { | ||
102 | '@id': 'as:shares', | ||
103 | '@type': '@id' | ||
104 | }, | ||
105 | comments: { | ||
106 | '@id': 'as:comments', | ||
107 | '@type': '@id' | ||
108 | } | ||
109 | }) | ||
110 | } | ||
111 | |||
112 | context.push(additional) | ||
16 | } | 113 | } |
17 | 114 | ||
18 | if (type === 'All') { | 115 | return { |
19 | Object.assign(base, { | 116 | '@context': context |
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 | } | 117 | } |
118 | } | ||
99 | 119 | ||
100 | return Object.assign({}, data, { | 120 | function activityPubContextify <T> (data: T, type: ContextType = 'All') { |
101 | '@context': [ | 121 | return Object.assign({}, data, getContextData(type)) |
102 | 'https://www.w3.org/ns/activitystreams', | ||
103 | 'https://w3id.org/security/v1', | ||
104 | base | ||
105 | ] | ||
106 | }) | ||
107 | } | 122 | } |
108 | 123 | ||
109 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> | 124 | type ActivityPubCollectionPaginationHandler = (start: number, count: number) => Bluebird<ResultList<any>> | Promise<ResultList<any>> |
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 3585d704a..8bdcf6417 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts | |||
@@ -16,6 +16,7 @@ import { | |||
16 | MVideoRedundancyFileVideo, | 16 | MVideoRedundancyFileVideo, |
17 | MVideoRedundancyStreamingPlaylistVideo | 17 | MVideoRedundancyStreamingPlaylistVideo |
18 | } from '../../../typings/models' | 18 | } from '../../../typings/models' |
19 | import { ContextType } from '@server/helpers/activitypub' | ||
19 | 20 | ||
20 | async function sendCreateVideo (video: MVideoAP, t: Transaction) { | 21 | async function sendCreateVideo (video: MVideoAP, t: Transaction) { |
21 | if (!video.hasPrivacyForFederation()) return undefined | 22 | if (!video.hasPrivacyForFederation()) return undefined |
@@ -42,7 +43,8 @@ async function sendCreateCacheFile ( | |||
42 | byActor, | 43 | byActor, |
43 | video, | 44 | video, |
44 | url: fileRedundancy.url, | 45 | url: fileRedundancy.url, |
45 | object: fileRedundancy.toActivityPubObject() | 46 | object: fileRedundancy.toActivityPubObject(), |
47 | contextType: 'CacheFile' | ||
46 | }) | 48 | }) |
47 | } | 49 | } |
48 | 50 | ||
@@ -135,6 +137,7 @@ async function sendVideoRelatedCreateActivity (options: { | |||
135 | url: string | 137 | url: string |
136 | object: any | 138 | object: any |
137 | transaction?: Transaction | 139 | transaction?: Transaction |
140 | contextType?: ContextType | ||
138 | }) { | 141 | }) { |
139 | const activityBuilder = (audience: ActivityAudience) => { | 142 | const activityBuilder = (audience: ActivityAudience) => { |
140 | return buildCreateActivity(options.url, options.byActor, options.object, audience) | 143 | return buildCreateActivity(options.url, options.byActor, options.object, audience) |
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index cb500bd34..2b01ca5e7 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -84,7 +84,7 @@ async function sendUpdateCacheFile (byActor: MActorLight, redundancyModel: MVide | |||
84 | return buildUpdateActivity(url, byActor, redundancyObject, audience) | 84 | return buildUpdateActivity(url, byActor, redundancyObject, audience) |
85 | } | 85 | } |
86 | 86 | ||
87 | return sendVideoRelatedActivity(activityBuilder, { byActor, video }) | 87 | return sendVideoRelatedActivity(activityBuilder, { byActor, video, contextType: 'CacheFile' }) |
88 | } | 88 | } |
89 | 89 | ||
90 | async function sendUpdateVideoPlaylist (videoPlaylist: MVideoPlaylistFull, t: Transaction) { | 90 | async function sendUpdateVideoPlaylist (videoPlaylist: MVideoPlaylistFull, t: Transaction) { |