aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-update.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-update.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-update.ts')
-rw-r--r--server/lib/activitypub/send/send-update.ts38
1 files changed, 27 insertions, 11 deletions
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index 6f1d80898..605473338 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -7,11 +7,11 @@ import { VideoModel } from '../../../models/video/video'
7import { VideoChannelModel } from '../../../models/video/video-channel' 7import { VideoChannelModel } from '../../../models/video/video-channel'
8import { VideoShareModel } from '../../../models/video/video-share' 8import { VideoShareModel } from '../../../models/video/video-share'
9import { getUpdateActivityPubUrl } from '../url' 9import { getUpdateActivityPubUrl } from '../url'
10import { broadcastToFollowers } from './utils' 10import { broadcastToFollowers, unicastTo } from './utils'
11import { audiencify, getAudience } from '../audience' 11import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience'
12import { logger } from '../../../helpers/logger' 12import { logger } from '../../../helpers/logger'
13import { videoFeedsValidator } from '../../../middlewares/validators'
14import { VideoCaptionModel } from '../../../models/video/video-caption' 13import { VideoCaptionModel } from '../../../models/video/video-caption'
14import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
15 15
16async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByActor?: ActorModel) { 16async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByActor?: ActorModel) {
17 logger.info('Creating job to update video %s.', video.url) 17 logger.info('Creating job to update video %s.', video.url)
@@ -26,12 +26,12 @@ async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByAct
26 const videoObject = video.toActivityPubObject() 26 const videoObject = video.toActivityPubObject()
27 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) 27 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
28 28
29 const data = updateActivityData(url, byActor, videoObject, audience) 29 const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience)
30 30
31 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) 31 const actorsInvolved = await getActorsInvolvedInVideo(video, t)
32 actorsInvolved.push(byActor) 32 if (overrodeByActor) actorsInvolved.push(overrodeByActor)
33 33
34 return broadcastToFollowers(data, byActor, actorsInvolved, t) 34 return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t)
35} 35}
36 36
37async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) { 37async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) {
@@ -42,7 +42,7 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod
42 const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) 42 const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
43 const accountOrChannelObject = accountOrChannel.toActivityPubObject() 43 const accountOrChannelObject = accountOrChannel.toActivityPubObject()
44 const audience = getAudience(byActor) 44 const audience = getAudience(byActor)
45 const data = updateActivityData(url, byActor, accountOrChannelObject, audience) 45 const updateActivity = buildUpdateActivity(url, byActor, accountOrChannelObject, audience)
46 46
47 let actorsInvolved: ActorModel[] 47 let actorsInvolved: ActorModel[]
48 if (accountOrChannel instanceof AccountModel) { 48 if (accountOrChannel instanceof AccountModel) {
@@ -55,19 +55,35 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod
55 55
56 actorsInvolved.push(byActor) 56 actorsInvolved.push(byActor)
57 57
58 return broadcastToFollowers(data, byActor, actorsInvolved, t) 58 return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t)
59}
60
61async function sendUpdateCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel) {
62 logger.info('Creating job to update cache file %s.', redundancyModel.url)
63
64 const url = getUpdateActivityPubUrl(redundancyModel.url, redundancyModel.updatedAt.toISOString())
65 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(redundancyModel.VideoFile.Video.id)
66
67 const redundancyObject = redundancyModel.toActivityPubObject()
68
69 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, undefined)
70 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
71
72 const updateActivity = buildUpdateActivity(url, byActor, redundancyObject, audience)
73 return unicastTo(updateActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
59} 74}
60 75
61// --------------------------------------------------------------------------- 76// ---------------------------------------------------------------------------
62 77
63export { 78export {
64 sendUpdateActor, 79 sendUpdateActor,
65 sendUpdateVideo 80 sendUpdateVideo,
81 sendUpdateCacheFile
66} 82}
67 83
68// --------------------------------------------------------------------------- 84// ---------------------------------------------------------------------------
69 85
70function updateActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate { 86function buildUpdateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate {
71 if (!audience) audience = getAudience(byActor) 87 if (!audience) audience = getAudience(byActor)
72 88
73 return audiencify( 89 return audiencify(