diff options
Diffstat (limited to 'server/lib/activitypub/share.ts')
-rw-r--r-- | server/lib/activitypub/share.ts | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts index c22fa0893..327955dd2 100644 --- a/server/lib/activitypub/share.ts +++ b/server/lib/activitypub/share.ts | |||
@@ -40,23 +40,7 @@ async function changeVideoChannelShare ( | |||
40 | async function addVideoShares (shareUrls: string[], video: MVideoId) { | 40 | async function addVideoShares (shareUrls: string[], video: MVideoId) { |
41 | await Bluebird.map(shareUrls, async shareUrl => { | 41 | await Bluebird.map(shareUrls, async shareUrl => { |
42 | try { | 42 | try { |
43 | const { body } = await doJSONRequest<any>(shareUrl, { activityPub: true }) | 43 | await addVideoShare(shareUrl, video) |
44 | if (!body || !body.actor) throw new Error('Body or body actor is invalid') | ||
45 | |||
46 | const actorUrl = getAPId(body.actor) | ||
47 | if (checkUrlsSameHost(shareUrl, actorUrl) !== true) { | ||
48 | throw new Error(`Actor url ${actorUrl} has not the same host than the share url ${shareUrl}`) | ||
49 | } | ||
50 | |||
51 | const actor = await getOrCreateActorAndServerAndModel(actorUrl) | ||
52 | |||
53 | const entry = { | ||
54 | actorId: actor.id, | ||
55 | videoId: video.id, | ||
56 | url: shareUrl | ||
57 | } | ||
58 | |||
59 | await VideoShareModel.upsert(entry) | ||
60 | } catch (err) { | 44 | } catch (err) { |
61 | logger.warn('Cannot add share %s.', shareUrl, { err }) | 45 | logger.warn('Cannot add share %s.', shareUrl, { err }) |
62 | } | 46 | } |
@@ -71,6 +55,26 @@ export { | |||
71 | 55 | ||
72 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
73 | 57 | ||
58 | async function addVideoShare (shareUrl: string, video: MVideoId) { | ||
59 | const { body } = await doJSONRequest<any>(shareUrl, { activityPub: true }) | ||
60 | if (!body || !body.actor) throw new Error('Body or body actor is invalid') | ||
61 | |||
62 | const actorUrl = getAPId(body.actor) | ||
63 | if (checkUrlsSameHost(shareUrl, actorUrl) !== true) { | ||
64 | throw new Error(`Actor url ${actorUrl} has not the same host than the share url ${shareUrl}`) | ||
65 | } | ||
66 | |||
67 | const actor = await getOrCreateActorAndServerAndModel(actorUrl) | ||
68 | |||
69 | const entry = { | ||
70 | actorId: actor.id, | ||
71 | videoId: video.id, | ||
72 | url: shareUrl | ||
73 | } | ||
74 | |||
75 | await VideoShareModel.upsert(entry) | ||
76 | } | ||
77 | |||
74 | async function shareByServer (video: MVideo, t: Transaction) { | 78 | async function shareByServer (video: MVideo, t: Transaction) { |
75 | const serverActor = await getServerActor() | 79 | const serverActor = await getServerActor() |
76 | 80 | ||