diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-13 17:39:41 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | 7a7724e66e4533523083e7336cd0d0c747c4a33b (patch) | |
tree | 805299eb9c6829158cd17e5a823a84a3a54d8209 /server/controllers/activitypub/inbox.ts | |
parent | 571389d43b8fc8aaf27e77c06f19b320b08dbbc9 (diff) | |
download | PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.gz PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.zst PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.zip |
Handle follow/accept
Diffstat (limited to 'server/controllers/activitypub/inbox.ts')
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 29 |
1 files changed, 22 insertions, 7 deletions
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 | |||
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, processFlagActivity, processUpdateActivity } from '../../lib' | 5 | import { processCreateActivity, processFlagActivity, processUpdateActivity } from '../../lib' |
6 | import { processAcceptActivity } from '../../lib/activitypub/process-accept' | ||
6 | import { processAddActivity } from '../../lib/activitypub/process-add' | 7 | import { processAddActivity } from '../../lib/activitypub/process-add' |
7 | import { asyncMiddleware, checkSignature, signatureValidator } from '../../middlewares' | 8 | import { processDeleteActivity } from '../../lib/activitypub/process-delete' |
9 | import { processFollowActivity } from '../../lib/activitypub/process-follow' | ||
10 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' | ||
8 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 11 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' |
12 | import { AccountInstance } from '../../models/account/account-interface' | ||
9 | 13 | ||
10 | const processActivity: { [ P in ActivityType ]: (activity: Activity) => Promise<any> } = { | 14 | const 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 | ||
17 | const inboxRouter = express.Router() | 24 | const inboxRouter = express.Router() |
18 | 25 | ||
19 | inboxRouter.post('/', | 26 | inboxRouter.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 | ||
33 | inboxRouter.post('/:nameWithHost/inbox', | ||
34 | signatureValidator, | ||
35 | asyncMiddleware(checkSignature), | ||
36 | localAccountValidator, | ||
37 | activityPubValidator, | ||
38 | asyncMiddleware(inboxController) | ||
39 | ) | ||
40 | |||
26 | // --------------------------------------------------------------------------- | 41 | // --------------------------------------------------------------------------- |
27 | 42 | ||
28 | export { | 43 | export { |
@@ -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 | ||
54 | async function processActivities (activities: Activity[]) { | 69 | async 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 | } |