aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-create.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-11 16:27:07 +0200
committerChocobozzz <me@florianbigard.com>2018-09-13 14:05:49 +0200
commitc48e82b5e0478434de30626d14594a97f2402e7c (patch)
treea78e5272bd0fe4f5b41831e571e02d05f1515b82 /server/lib/activitypub/send/send-create.ts
parenta651038487faa838bda3ce04695b08bc65baff70 (diff)
downloadPeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.gz
PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.tar.zst
PeerTube-c48e82b5e0478434de30626d14594a97f2402e7c.zip
Basic video redundancy implementation
Diffstat (limited to 'server/lib/activitypub/send/send-create.ts')
-rw-r--r--server/lib/activitypub/send/send-create.ts68
1 files changed, 42 insertions, 26 deletions
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index fc76cdd8a..6f89b1a22 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -17,6 +17,7 @@ import {
17 getVideoCommentAudience 17 getVideoCommentAudience
18} from '../audience' 18} from '../audience'
19import { logger } from '../../../helpers/logger' 19import { logger } from '../../../helpers/logger'
20import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
20 21
21async function sendCreateVideo (video: VideoModel, t: Transaction) { 22async function sendCreateVideo (video: VideoModel, t: Transaction) {
22 if (video.privacy === VideoPrivacy.PRIVATE) return undefined 23 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
@@ -27,12 +28,12 @@ async function sendCreateVideo (video: VideoModel, t: Transaction) {
27 const videoObject = video.toActivityPubObject() 28 const videoObject = video.toActivityPubObject()
28 29
29 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) 30 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
30 const data = createActivityData(video.url, byActor, videoObject, audience) 31 const createActivity = buildCreateActivity(video.url, byActor, videoObject, audience)
31 32
32 return broadcastToFollowers(data, byActor, [ byActor ], t) 33 return broadcastToFollowers(createActivity, byActor, [ byActor ], t)
33} 34}
34 35
35async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { 36async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel) {
36 if (!video.VideoChannel.Account.Actor.serverId) return // Local 37 if (!video.VideoChannel.Account.Actor.serverId) return // Local
37 38
38 const url = getVideoAbuseActivityPubUrl(videoAbuse) 39 const url = getVideoAbuseActivityPubUrl(videoAbuse)
@@ -40,9 +41,23 @@ async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel,
40 logger.info('Creating job to send video abuse %s.', url) 41 logger.info('Creating job to send video abuse %s.', url)
41 42
42 const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } 43 const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
43 const data = createActivityData(url, byActor, videoAbuse.toActivityPubObject(), audience) 44 const createActivity = buildCreateActivity(url, byActor, videoAbuse.toActivityPubObject(), audience)
44 45
45 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 46 return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
47}
48
49async function sendCreateCacheFile (byActor: ActorModel, fileRedundancy: VideoRedundancyModel) {
50 logger.info('Creating job to send file cache of %s.', fileRedundancy.url)
51
52 const redundancyObject = fileRedundancy.toActivityPubObject()
53
54 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(fileRedundancy.VideoFile.Video.id)
55 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, undefined)
56
57 const audience = getVideoAudience(video, actorsInvolvedInVideo)
58 const createActivity = buildCreateActivity(fileRedundancy.url, byActor, redundancyObject, audience)
59
60 return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
46} 61}
47 62
48async function sendCreateVideoComment (comment: VideoCommentModel, t: Transaction) { 63async function sendCreateVideoComment (comment: VideoCommentModel, t: Transaction) {
@@ -66,73 +81,73 @@ async function sendCreateVideoComment (comment: VideoCommentModel, t: Transactio
66 audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors)) 81 audience = getObjectFollowersAudience(actorsInvolvedInComment.concat(parentsCommentActors))
67 } 82 }
68 83
69 const data = createActivityData(comment.url, byActor, commentObject, audience) 84 const createActivity = buildCreateActivity(comment.url, byActor, commentObject, audience)
70 85
71 // This was a reply, send it to the parent actors 86 // This was a reply, send it to the parent actors
72 const actorsException = [ byActor ] 87 const actorsException = [ byActor ]
73 await broadcastToActors(data, byActor, parentsCommentActors, actorsException) 88 await broadcastToActors(createActivity, byActor, parentsCommentActors, actorsException)
74 89
75 // Broadcast to our followers 90 // Broadcast to our followers
76 await broadcastToFollowers(data, byActor, [ byActor ], t) 91 await broadcastToFollowers(createActivity, byActor, [ byActor ], t)
77 92
78 // Send to actors involved in the comment 93 // Send to actors involved in the comment
79 if (isOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException) 94 if (isOrigin) return broadcastToFollowers(createActivity, byActor, actorsInvolvedInComment, t, actorsException)
80 95
81 // Send to origin 96 // Send to origin
82 return unicastTo(data, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl) 97 return unicastTo(createActivity, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
83} 98}
84 99
85async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transaction) { 100async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transaction) {
86 logger.info('Creating job to send view of %s.', video.url) 101 logger.info('Creating job to send view of %s.', video.url)
87 102
88 const url = getVideoViewActivityPubUrl(byActor, video) 103 const url = getVideoViewActivityPubUrl(byActor, video)
89 const viewActivityData = createViewActivityData(byActor, video) 104 const viewActivity = buildViewActivity(byActor, video)
90 105
91 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 106 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
92 107
93 // Send to origin 108 // Send to origin
94 if (video.isOwned() === false) { 109 if (video.isOwned() === false) {
95 const audience = getVideoAudience(video, actorsInvolvedInVideo) 110 const audience = getVideoAudience(video, actorsInvolvedInVideo)
96 const data = createActivityData(url, byActor, viewActivityData, audience) 111 const createActivity = buildCreateActivity(url, byActor, viewActivity, audience)
97 112
98 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 113 return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
99 } 114 }
100 115
101 // Send to followers 116 // Send to followers
102 const audience = getObjectFollowersAudience(actorsInvolvedInVideo) 117 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
103 const data = createActivityData(url, byActor, viewActivityData, audience) 118 const createActivity = buildCreateActivity(url, byActor, viewActivity, audience)
104 119
105 // Use the server actor to send the view 120 // Use the server actor to send the view
106 const serverActor = await getServerActor() 121 const serverActor = await getServerActor()
107 const actorsException = [ byActor ] 122 const actorsException = [ byActor ]
108 return broadcastToFollowers(data, serverActor, actorsInvolvedInVideo, t, actorsException) 123 return broadcastToFollowers(createActivity, serverActor, actorsInvolvedInVideo, t, actorsException)
109} 124}
110 125
111async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Transaction) { 126async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
112 logger.info('Creating job to dislike %s.', video.url) 127 logger.info('Creating job to dislike %s.', video.url)
113 128
114 const url = getVideoDislikeActivityPubUrl(byActor, video) 129 const url = getVideoDislikeActivityPubUrl(byActor, video)
115 const dislikeActivityData = createDislikeActivityData(byActor, video) 130 const dislikeActivity = buildDislikeActivity(byActor, video)
116 131
117 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) 132 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
118 133
119 // Send to origin 134 // Send to origin
120 if (video.isOwned() === false) { 135 if (video.isOwned() === false) {
121 const audience = getVideoAudience(video, actorsInvolvedInVideo) 136 const audience = getVideoAudience(video, actorsInvolvedInVideo)
122 const data = createActivityData(url, byActor, dislikeActivityData, audience) 137 const createActivity = buildCreateActivity(url, byActor, dislikeActivity, audience)
123 138
124 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) 139 return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
125 } 140 }
126 141
127 // Send to followers 142 // Send to followers
128 const audience = getObjectFollowersAudience(actorsInvolvedInVideo) 143 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
129 const data = createActivityData(url, byActor, dislikeActivityData, audience) 144 const createActivity = buildCreateActivity(url, byActor, dislikeActivity, audience)
130 145
131 const actorsException = [ byActor ] 146 const actorsException = [ byActor ]
132 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, actorsException) 147 return broadcastToFollowers(createActivity, byActor, actorsInvolvedInVideo, t, actorsException)
133} 148}
134 149
135function createActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate { 150function buildCreateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate {
136 if (!audience) audience = getAudience(byActor) 151 if (!audience) audience = getAudience(byActor)
137 152
138 return audiencify( 153 return audiencify(
@@ -146,7 +161,7 @@ function createActivityData (url: string, byActor: ActorModel, object: any, audi
146 ) 161 )
147} 162}
148 163
149function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { 164function buildDislikeActivity (byActor: ActorModel, video: VideoModel) {
150 return { 165 return {
151 type: 'Dislike', 166 type: 'Dislike',
152 actor: byActor.url, 167 actor: byActor.url,
@@ -154,7 +169,7 @@ function createDislikeActivityData (byActor: ActorModel, video: VideoModel) {
154 } 169 }
155} 170}
156 171
157function createViewActivityData (byActor: ActorModel, video: VideoModel) { 172function buildViewActivity (byActor: ActorModel, video: VideoModel) {
158 return { 173 return {
159 type: 'View', 174 type: 'View',
160 actor: byActor.url, 175 actor: byActor.url,
@@ -167,9 +182,10 @@ function createViewActivityData (byActor: ActorModel, video: VideoModel) {
167export { 182export {
168 sendCreateVideo, 183 sendCreateVideo,
169 sendVideoAbuse, 184 sendVideoAbuse,
170 createActivityData, 185 buildCreateActivity,
171 sendCreateView, 186 sendCreateView,
172 sendCreateDislike, 187 sendCreateDislike,
173 createDislikeActivityData, 188 buildDislikeActivity,
174 sendCreateVideoComment 189 sendCreateVideoComment,
190 sendCreateCacheFile
175} 191}