diff options
Diffstat (limited to 'server/controllers/activitypub/inbox.ts')
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index 807d0bdf4..30e7f706b 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts | |||
@@ -1,27 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, ActivityType, RootActivity } from '../../../shared' | 2 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '../../../shared' |
3 | import { logger } from '../../helpers' | 3 | import { logger } from '../../helpers' |
4 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' | 4 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' |
5 | import { processCreateActivity, processUpdateActivity, processUndoActivity } from '../../lib' | 5 | import { processActivities } from '../../lib/activitypub/process/process' |
6 | import { processAcceptActivity } from '../../lib/activitypub/process/process-accept' | ||
7 | import { processAddActivity } from '../../lib/activitypub/process/process-add' | ||
8 | import { processAnnounceActivity } from '../../lib/activitypub/process/process-announce' | ||
9 | import { processDeleteActivity } from '../../lib/activitypub/process/process-delete' | ||
10 | import { processFollowActivity } from '../../lib/activitypub/process/process-follow' | ||
11 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' | 6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' |
12 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' |
13 | import { AccountInstance } from '../../models/account/account-interface' | ||
14 | |||
15 | const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxAccount?: AccountInstance) => Promise<any> } = { | ||
16 | Create: processCreateActivity, | ||
17 | Add: processAddActivity, | ||
18 | Update: processUpdateActivity, | ||
19 | Delete: processDeleteActivity, | ||
20 | Follow: processFollowActivity, | ||
21 | Accept: processAcceptActivity, | ||
22 | Announce: processAnnounceActivity, | ||
23 | Undo: processUndoActivity | ||
24 | } | ||
25 | 8 | ||
26 | const inboxRouter = express.Router() | 9 | const inboxRouter = express.Router() |
27 | 10 | ||
@@ -69,15 +52,3 @@ async function inboxController (req: express.Request, res: express.Response, nex | |||
69 | 52 | ||
70 | res.status(204).end() | 53 | res.status(204).end() |
71 | } | 54 | } |
72 | |||
73 | async function processActivities (activities: Activity[], inboxAccount?: AccountInstance) { | ||
74 | for (const activity of activities) { | ||
75 | const activityProcessor = processActivity[activity.type] | ||
76 | if (activityProcessor === undefined) { | ||
77 | logger.warn('Unknown activity type %s.', activity.type, { activityId: activity.id }) | ||
78 | continue | ||
79 | } | ||
80 | |||
81 | await activityProcessor(activity, inboxAccount) | ||
82 | } | ||
83 | } | ||