aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/client.ts31
-rw-r--r--server/controllers/activitypub/inbox.ts10
-rw-r--r--server/controllers/activitypub/outbox.ts20
3 files changed, 25 insertions, 36 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 72b216254..8c6294ff7 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -2,20 +2,13 @@
2import * as express from 'express' 2import * as express from 'express'
3import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' 3import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers'
4import { ACTIVITY_PUB, CONFIG } from '../../initializers' 4import { ACTIVITY_PUB, CONFIG } from '../../initializers'
5import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send' 5import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send'
6import { buildVideoAnnounceToFollowers } from '../../lib/index'
7import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' 6import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares'
8import { 7import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators'
9 videoChannelsGetValidator,
10 videoChannelsShareValidator,
11 videosGetValidator,
12 videosShareValidator
13} from '../../middlewares/validators'
14import { AccountModel } from '../../models/account/account' 8import { AccountModel } from '../../models/account/account'
15import { AccountFollowModel } from '../../models/account/account-follow' 9import { ActorFollowModel } from '../../models/activitypub/actor-follow'
16import { VideoModel } from '../../models/video/video' 10import { VideoModel } from '../../models/video/video'
17import { VideoChannelModel } from '../../models/video/video-channel' 11import { VideoChannelModel } from '../../models/video/video-channel'
18import { VideoChannelShareModel } from '../../models/video/video-channel-share'
19import { VideoShareModel } from '../../models/video/video-share' 12import { VideoShareModel } from '../../models/video/video-share'
20 13
21const activityPubClientRouter = express.Router() 14const activityPubClientRouter = express.Router()
@@ -50,11 +43,6 @@ activityPubClientRouter.get('/video-channels/:id',
50 executeIfActivityPub(asyncMiddleware(videoChannelController)) 43 executeIfActivityPub(asyncMiddleware(videoChannelController))
51) 44)
52 45
53activityPubClientRouter.get('/video-channels/:id/announces/:accountId',
54 executeIfActivityPub(asyncMiddleware(videoChannelsShareValidator)),
55 executeIfActivityPub(asyncMiddleware(videoChannelAnnounceController))
56)
57
58// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------
59 47
60export { 48export {
@@ -75,7 +63,7 @@ async function accountFollowersController (req: express.Request, res: express.Re
75 const page = req.query.page || 1 63 const page = req.query.page || 1
76 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 64 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
77 65
78 const result = await AccountFollowModel.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) 66 const result = await ActorFollowModel.listAcceptedFollowerUrlsForApi([ account.Actor.id ], undefined, start, count)
79 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) 67 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
80 68
81 return res.json(activityPubResult) 69 return res.json(activityPubResult)
@@ -87,7 +75,7 @@ async function accountFollowingController (req: express.Request, res: express.Re
87 const page = req.query.page || 1 75 const page = req.query.page || 1
88 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 76 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
89 77
90 const result = await AccountFollowModel.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) 78 const result = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ account.Actor.id ], undefined, start, count)
91 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) 79 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
92 80
93 return res.json(activityPubResult) 81 return res.json(activityPubResult)
@@ -101,14 +89,7 @@ function videoController (req: express.Request, res: express.Response, next: exp
101 89
102async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 90async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
103 const share = res.locals.videoShare as VideoShareModel 91 const share = res.locals.videoShare as VideoShareModel
104 const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) 92 const object = await buildVideoAnnounceToFollowers(share.Actor, res.locals.video, undefined)
105
106 return res.json(object)
107}
108
109async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
110 const share = res.locals.videoChannelShare as VideoChannelShareModel
111 const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined)
112 93
113 return res.json(object) 94 return res.json(object)
114} 95}
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index 88a0834f6..8332eabb1 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -5,6 +5,7 @@ import { isActivityValid } from '../../helpers/custom-validators/activitypub/act
5import { processActivities } from '../../lib/activitypub/process/process' 5import { processActivities } from '../../lib/activitypub/process/process'
6import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' 6import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares'
7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
8import { ActorModel } from '../../models/activitypub/actor'
8 9
9const inboxRouter = express.Router() 10const inboxRouter = express.Router()
10 11
@@ -48,7 +49,14 @@ async function inboxController (req: express.Request, res: express.Response, nex
48 activities = activities.filter(a => isActivityValid(a)) 49 activities = activities.filter(a => isActivityValid(a))
49 logger.debug('We keep %d activities.', activities.length, { activities }) 50 logger.debug('We keep %d activities.', activities.length, { activities })
50 51
51 await processActivities(activities, res.locals.signature.account, res.locals.account) 52 let specificActor: ActorModel = undefined
53 if (res.locals.account) {
54 specificActor = res.locals.account
55 } else if (res.locals.videoChannel) {
56 specificActor = res.locals.videoChannel
57 }
58
59 await processActivities(activities, res.locals.signature.actor, specificActor)
52 60
53 res.status(204).end() 61 res.status(204).end()
54} 62}
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index 6ed8a3454..01ba253c6 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -3,9 +3,8 @@ import { Activity } from '../../../shared/models/activitypub/activity'
3import { activityPubCollectionPagination } from '../../helpers/activitypub' 3import { activityPubCollectionPagination } from '../../helpers/activitypub'
4import { pageToStartAndCount } from '../../helpers/core-utils' 4import { pageToStartAndCount } from '../../helpers/core-utils'
5import { ACTIVITY_PUB } from '../../initializers/constants' 5import { ACTIVITY_PUB } from '../../initializers/constants'
6import { addActivityData } from '../../lib/activitypub/send/send-add' 6import { announceActivityData, createActivityData } from '../../lib/activitypub/send'
7import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' 7import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
8import { announceActivityData } from '../../lib/index'
9import { asyncMiddleware, localAccountValidator } from '../../middlewares' 8import { asyncMiddleware, localAccountValidator } from '../../middlewares'
10import { AccountModel } from '../../models/account/account' 9import { AccountModel } from '../../models/account/account'
11import { VideoModel } from '../../models/video/video' 10import { VideoModel } from '../../models/video/video'
@@ -27,29 +26,30 @@ export {
27 26
28async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { 27async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) {
29 const account: AccountModel = res.locals.account 28 const account: AccountModel = res.locals.account
29 const actor = account.Actor
30 30
31 const page = req.query.page || 1 31 const page = req.query.page || 1
32 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 32 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
33 33
34 const data = await VideoModel.listAllAndSharedByAccountForOutbox(account.id, start, count) 34 const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count)
35 const activities: Activity[] = [] 35 const activities: Activity[] = []
36 36
37 for (const video of data.data) { 37 for (const video of data.data) {
38 const videoObject = video.toActivityPubObject() 38 const videoObject = video.toActivityPubObject()
39 39
40 // This is a shared video
41 const videoChannel = video.VideoChannel 40 const videoChannel = video.VideoChannel
41 // This is a shared video
42 if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { 42 if (video.VideoShares !== undefined && video.VideoShares.length !== 0) {
43 const addActivity = await addActivityData(video.url, videoChannel.Account, video, videoChannel.Actor.url, videoObject, undefined) 43 const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined)
44 44
45 const url = getAnnounceActivityPubUrl(video.url, account) 45 const url = getAnnounceActivityPubUrl(video.url, actor)
46 const announceActivity = await announceActivityData(url, account, addActivity, undefined) 46 const announceActivity = await announceActivityData(url, actor, createActivity, undefined)
47 47
48 activities.push(announceActivity) 48 activities.push(announceActivity)
49 } else { 49 } else {
50 const addActivity = await addActivityData(video.url, account, video, videoChannel.Actor.url, videoObject, undefined) 50 const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined)
51 51
52 activities.push(addActivity) 52 activities.push(createActivity)
53 } 53 }
54 } 54 }
55 55
@@ -57,7 +57,7 @@ async function outboxController (req: express.Request, res: express.Response, ne
57 data: activities, 57 data: activities,
58 total: data.total 58 total: data.total
59 } 59 }
60 const json = activityPubCollectionPagination(account.url + '/outbox', page, newResult) 60 const json = activityPubCollectionPagination(account.Actor.url + '/outbox', page, newResult)
61 61
62 return res.json(json).end() 62 return res.json(json).end()
63} 63}