aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/share.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-03 14:30:09 +0200
committerChocobozzz <me@florianbigard.com>2021-06-03 16:40:32 +0200
commit49af5ac8c2653cb0ef23479c9d3256c5b724d49d (patch)
tree6783df1833b13e141cfd5dc0177531887c4a4e2e /server/lib/activitypub/share.ts
parent9777fe9eebe53debdf45091cab98f72a5987e05a (diff)
downloadPeerTube-49af5ac8c2653cb0ef23479c9d3256c5b724d49d.tar.gz
PeerTube-49af5ac8c2653cb0ef23479c9d3256c5b724d49d.tar.zst
PeerTube-49af5ac8c2653cb0ef23479c9d3256c5b724d49d.zip
Refactor AP playlists
Diffstat (limited to 'server/lib/activitypub/share.ts')
-rw-r--r--server/lib/activitypub/share.ts38
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 (
40async function addVideoShares (shareUrls: string[], video: MVideoId) { 40async 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
58async 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
74async function shareByServer (video: MVideo, t: Transaction) { 78async function shareByServer (video: MVideo, t: Transaction) {
75 const serverActor = await getServerActor() 79 const serverActor = await getServerActor()
76 80