aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/client.ts8
-rw-r--r--server/controllers/activitypub/inbox.ts29
-rw-r--r--server/controllers/activitypub/index.ts2
-rw-r--r--server/controllers/activitypub/videos.ts61
4 files changed, 27 insertions, 73 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 28d08b3f4..5cfbc2f1d 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -16,12 +16,12 @@ activityPubClientRouter.get('/account/:name',
16 executeIfActivityPub(asyncMiddleware(accountController)) 16 executeIfActivityPub(asyncMiddleware(accountController))
17) 17)
18 18
19activityPubClientRouter.get('/account/:name/followers', 19activityPubClientRouter.get('/account/:nameWithHost/followers',
20 executeIfActivityPub(localAccountValidator), 20 executeIfActivityPub(localAccountValidator),
21 executeIfActivityPub(asyncMiddleware(accountFollowersController)) 21 executeIfActivityPub(asyncMiddleware(accountFollowersController))
22) 22)
23 23
24activityPubClientRouter.get('/account/:name/following', 24activityPubClientRouter.get('/account/:nameWithHost/following',
25 executeIfActivityPub(localAccountValidator), 25 executeIfActivityPub(localAccountValidator),
26 executeIfActivityPub(asyncMiddleware(accountFollowingController)) 26 executeIfActivityPub(asyncMiddleware(accountFollowingController))
27) 27)
@@ -46,7 +46,7 @@ async function accountFollowersController (req: express.Request, res: express.Re
46 const page = req.params.page || 1 46 const page = req.params.page || 1
47 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 47 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
48 48
49 const result = await db.Account.listFollowerUrlsForApi(account.name, start, count) 49 const result = await db.Account.listFollowerUrlsForApi(account.id, start, count)
50 const activityPubResult = activityPubCollectionPagination(req.url, page, result) 50 const activityPubResult = activityPubCollectionPagination(req.url, page, result)
51 51
52 return res.json(activityPubResult) 52 return res.json(activityPubResult)
@@ -58,7 +58,7 @@ async function accountFollowingController (req: express.Request, res: express.Re
58 const page = req.params.page || 1 58 const page = req.params.page || 1
59 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 59 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
60 60
61 const result = await db.Account.listFollowingUrlsForApi(account.name, start, count) 61 const result = await db.Account.listFollowingUrlsForApi(account.id, start, count)
62 const activityPubResult = activityPubCollectionPagination(req.url, page, result) 62 const activityPubResult = activityPubCollectionPagination(req.url, page, result)
63 63
64 return res.json(activityPubResult) 64 return res.json(activityPubResult)
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index eee217650..eedb518b9 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -3,26 +3,41 @@ import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, Activity
3import { logger } from '../../helpers' 3import { logger } from '../../helpers'
4import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' 4import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity'
5import { processCreateActivity, processFlagActivity, processUpdateActivity } from '../../lib' 5import { processCreateActivity, processFlagActivity, processUpdateActivity } from '../../lib'
6import { processAcceptActivity } from '../../lib/activitypub/process-accept'
6import { processAddActivity } from '../../lib/activitypub/process-add' 7import { processAddActivity } from '../../lib/activitypub/process-add'
7import { asyncMiddleware, checkSignature, signatureValidator } from '../../middlewares' 8import { processDeleteActivity } from '../../lib/activitypub/process-delete'
9import { processFollowActivity } from '../../lib/activitypub/process-follow'
10import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares'
8import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 11import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
12import { AccountInstance } from '../../models/account/account-interface'
9 13
10const processActivity: { [ P in ActivityType ]: (activity: Activity) => Promise<any> } = { 14const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccount?: AccountInstance) => Promise<any> } = {
11 Create: processCreateActivity, 15 Create: processCreateActivity,
12 Add: processAddActivity, 16 Add: processAddActivity,
13 Update: processUpdateActivity, 17 Update: processUpdateActivity,
14 Flag: processFlagActivity 18 Flag: processFlagActivity,
19 Delete: processDeleteActivity,
20 Follow: processFollowActivity,
21 Accept: processAcceptActivity
15} 22}
16 23
17const inboxRouter = express.Router() 24const inboxRouter = express.Router()
18 25
19inboxRouter.post('/', 26inboxRouter.post('/inbox',
20 signatureValidator, 27 signatureValidator,
21 asyncMiddleware(checkSignature), 28 asyncMiddleware(checkSignature),
22 activityPubValidator, 29 activityPubValidator,
23 asyncMiddleware(inboxController) 30 asyncMiddleware(inboxController)
24) 31)
25 32
33inboxRouter.post('/:nameWithHost/inbox',
34 signatureValidator,
35 asyncMiddleware(checkSignature),
36 localAccountValidator,
37 activityPubValidator,
38 asyncMiddleware(inboxController)
39)
40
26// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
27 42
28export { 43export {
@@ -46,12 +61,12 @@ async function inboxController (req: express.Request, res: express.Response, nex
46 // Only keep activities we are able to process 61 // Only keep activities we are able to process
47 activities = activities.filter(a => isActivityValid(a)) 62 activities = activities.filter(a => isActivityValid(a))
48 63
49 await processActivities(activities) 64 await processActivities(activities, res.locals.account)
50 65
51 res.status(204).end() 66 res.status(204).end()
52} 67}
53 68
54async function processActivities (activities: Activity[]) { 69async function processActivities (activities: Activity[], inboxAccount?: AccountInstance) {
55 for (const activity of activities) { 70 for (const activity of activities) {
56 const activityProcessor = processActivity[activity.type] 71 const activityProcessor = processActivity[activity.type]
57 if (activityProcessor === undefined) { 72 if (activityProcessor === undefined) {
@@ -59,6 +74,6 @@ async function processActivities (activities: Activity[]) {
59 continue 74 continue
60 } 75 }
61 76
62 await activityProcessor(activity) 77 await activityProcessor(activity, inboxAccount)
63 } 78 }
64} 79}
diff --git a/server/controllers/activitypub/index.ts b/server/controllers/activitypub/index.ts
index 2b0e2a489..6c7bafc6e 100644
--- a/server/controllers/activitypub/index.ts
+++ b/server/controllers/activitypub/index.ts
@@ -6,7 +6,7 @@ import { activityPubClientRouter } from './client'
6 6
7const remoteRouter = express.Router() 7const remoteRouter = express.Router()
8 8
9remoteRouter.use('/inbox', inboxRouter) 9remoteRouter.use('/', inboxRouter)
10remoteRouter.use('/', activityPubClientRouter) 10remoteRouter.use('/', activityPubClientRouter)
11remoteRouter.use('/*', badRequest) 11remoteRouter.use('/*', badRequest)
12 12
diff --git a/server/controllers/activitypub/videos.ts b/server/controllers/activitypub/videos.ts
index a9b31bf75..98894379f 100644
--- a/server/controllers/activitypub/videos.ts
+++ b/server/controllers/activitypub/videos.ts
@@ -224,67 +224,6 @@
224// logger.info('Remote video with uuid %s quick and dirty updated', videoUUID) 224// logger.info('Remote video with uuid %s quick and dirty updated', videoUUID)
225// } 225// }
226// 226//
227// async function removeRemoteVideoRetryWrapper (videoToRemoveData: RemoteVideoRemoveData, fromPod: PodInstance) {
228// const options = {
229// arguments: [ videoToRemoveData, fromPod ],
230// errorMessage: 'Cannot remove the remote video channel with many retries.'
231// }
232//
233// await retryTransactionWrapper(removeRemoteVideo, options)
234// }
235//
236// async function removeRemoteVideo (videoToRemoveData: RemoteVideoRemoveData, fromPod: PodInstance) {
237// logger.debug('Removing remote video "%s".', videoToRemoveData.uuid)
238//
239// await db.sequelize.transaction(async t => {
240// // We need the instance because we have to remove some other stuffs (thumbnail etc)
241// const videoInstance = await fetchVideoByHostAndUUID(fromPod.host, videoToRemoveData.uuid, t)
242// await videoInstance.destroy({ transaction: t })
243// })
244//
245// logger.info('Remote video with uuid %s removed.', videoToRemoveData.uuid)
246// }
247//
248// async function removeRemoteVideoAccountRetryWrapper (accountAttributesToRemove: RemoteVideoAccountRemoveData, fromPod: PodInstance) {
249// const options = {
250// arguments: [ accountAttributesToRemove, fromPod ],
251// errorMessage: 'Cannot remove the remote video account with many retries.'
252// }
253//
254// await retryTransactionWrapper(removeRemoteVideoAccount, options)
255// }
256//
257// async function removeRemoteVideoAccount (accountAttributesToRemove: RemoteVideoAccountRemoveData, fromPod: PodInstance) {
258// logger.debug('Removing remote video account "%s".', accountAttributesToRemove.uuid)
259//
260// await db.sequelize.transaction(async t => {
261// const videoAccount = await db.Account.loadAccountByPodAndUUID(accountAttributesToRemove.uuid, fromPod.id, t)
262// await videoAccount.destroy({ transaction: t })
263// })
264//
265// logger.info('Remote video account with uuid %s removed.', accountAttributesToRemove.uuid)
266// }
267//
268// async function removeRemoteVideoChannelRetryWrapper (videoChannelAttributesToRemove: RemoteVideoChannelRemoveData, fromPod: PodInstance) {
269// const options = {
270// arguments: [ videoChannelAttributesToRemove, fromPod ],
271// errorMessage: 'Cannot remove the remote video channel with many retries.'
272// }
273//
274// await retryTransactionWrapper(removeRemoteVideoChannel, options)
275// }
276//
277// async function removeRemoteVideoChannel (videoChannelAttributesToRemove: RemoteVideoChannelRemoveData, fromPod: PodInstance) {
278// logger.debug('Removing remote video channel "%s".', videoChannelAttributesToRemove.uuid)
279//
280// await db.sequelize.transaction(async t => {
281// const videoChannel = await fetchVideoChannelByHostAndUUID(fromPod.host, videoChannelAttributesToRemove.uuid, t)
282// await videoChannel.destroy({ transaction: t })
283// })
284//
285// logger.info('Remote video channel with uuid %s removed.', videoChannelAttributesToRemove.uuid)
286// }
287//
288// async function reportAbuseRemoteVideoRetryWrapper (reportData: RemoteVideoReportAbuseData, fromPod: PodInstance) { 227// async function reportAbuseRemoteVideoRetryWrapper (reportData: RemoteVideoReportAbuseData, fromPod: PodInstance) {
289// const options = { 228// const options = {
290// arguments: [ reportData, fromPod ], 229// arguments: [ reportData, fromPod ],