diff options
Diffstat (limited to 'server/lib/activitypub/share.ts')
-rw-r--r-- | server/lib/activitypub/share.ts | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index 5dcba778c..1767df0ae 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts | |||
@@ -11,7 +11,7 @@ import { doRequest } from '../../helpers/requests' | |||
11 | import { getOrCreateActorAndServerAndModel } from './actor' | 11 | import { getOrCreateActorAndServerAndModel } from './actor' |
12 | import { logger } from '../../helpers/logger' | 12 | import { logger } from '../../helpers/logger' |
13 | import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers' | 13 | import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers' |
14 | import { checkUrlsSameHost, getAPUrl } from '../../helpers/activitypub' | 14 | import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' |
15 | 15 | ||
16 | async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { | 16 | async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) { |
17 | if (video.privacy === VideoPrivacy.PRIVATE) return undefined | 17 | if (video.privacy === VideoPrivacy.PRIVATE) return undefined |
@@ -41,7 +41,7 @@ async function addVideoShares (shareUrls: string[], instance: VideoModel) { | |||
41 | }) | 41 | }) |
42 | if (!body || !body.actor) throw new Error('Body or body actor is invalid') | 42 | if (!body || !body.actor) throw new Error('Body or body actor is invalid') |
43 | 43 | ||
44 | const actorUrl = getAPUrl(body.actor) | 44 | const actorUrl = getAPId(body.actor) |
45 | if (checkUrlsSameHost(shareUrl, actorUrl) !== true) { | 45 | if (checkUrlsSameHost(shareUrl, actorUrl) !== true) { |
46 | throw new Error(`Actor url ${actorUrl} has not the same host than the share url ${shareUrl}`) | 46 | throw new Error(`Actor url ${actorUrl} has not the same host than the share url ${shareUrl}`) |
47 | } | 47 | } |
@@ -78,7 +78,7 @@ async function shareByServer (video: VideoModel, t: Transaction) { | |||
78 | const serverActor = await getServerActor() | 78 | const serverActor = await getServerActor() |
79 | 79 | ||
80 | const serverShareUrl = getVideoAnnounceActivityPubUrl(serverActor, video) | 80 | const serverShareUrl = getVideoAnnounceActivityPubUrl(serverActor, video) |
81 | return VideoShareModel.findOrCreate({ | 81 | const [ serverShare ] = await VideoShareModel.findOrCreate({ |
82 | defaults: { | 82 | defaults: { |
83 | actorId: serverActor.id, | 83 | actorId: serverActor.id, |
84 | videoId: video.id, | 84 | videoId: video.id, |
@@ -88,16 +88,14 @@ async function shareByServer (video: VideoModel, t: Transaction) { | |||
88 | url: serverShareUrl | 88 | url: serverShareUrl |
89 | }, | 89 | }, |
90 | transaction: t | 90 | transaction: t |
91 | }).then(([ serverShare, created ]) => { | ||
92 | if (created) return sendVideoAnnounce(serverActor, serverShare, video, t) | ||
93 | |||
94 | return undefined | ||
95 | }) | 91 | }) |
92 | |||
93 | return sendVideoAnnounce(serverActor, serverShare, video, t) | ||
96 | } | 94 | } |
97 | 95 | ||
98 | async function shareByVideoChannel (video: VideoModel, t: Transaction) { | 96 | async function shareByVideoChannel (video: VideoModel, t: Transaction) { |
99 | const videoChannelShareUrl = getVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video) | 97 | const videoChannelShareUrl = getVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video) |
100 | return VideoShareModel.findOrCreate({ | 98 | const [ videoChannelShare ] = await VideoShareModel.findOrCreate({ |
101 | defaults: { | 99 | defaults: { |
102 | actorId: video.VideoChannel.actorId, | 100 | actorId: video.VideoChannel.actorId, |
103 | videoId: video.id, | 101 | videoId: video.id, |
@@ -107,11 +105,9 @@ async function shareByVideoChannel (video: VideoModel, t: Transaction) { | |||
107 | url: videoChannelShareUrl | 105 | url: videoChannelShareUrl |
108 | }, | 106 | }, |
109 | transaction: t | 107 | transaction: t |
110 | }).then(([ videoChannelShare, created ]) => { | ||
111 | if (created) return sendVideoAnnounce(video.VideoChannel.Actor, videoChannelShare, video, t) | ||
112 | |||
113 | return undefined | ||
114 | }) | 108 | }) |
109 | |||
110 | return sendVideoAnnounce(video.VideoChannel.Actor, videoChannelShare, video, t) | ||
115 | } | 111 | } |
116 | 112 | ||
117 | async function undoShareByVideoChannel (video: VideoModel, oldVideoChannel: VideoChannelModel, t: Transaction) { | 113 | async function undoShareByVideoChannel (video: VideoModel, oldVideoChannel: VideoChannelModel, t: Transaction) { |