diff options
Diffstat (limited to 'server/controllers/activitypub/inbox.ts')
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts deleted file mode 100644 index 862c7baf1..000000000 --- a/server/controllers/activitypub/inbox.ts +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { InboxManager } from '@server/lib/activitypub/inbox-manager' | ||
3 | import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActivity } from '@shared/models' | ||
4 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' | ||
5 | import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity' | ||
6 | import { logger } from '../../helpers/logger' | ||
7 | import { | ||
8 | activityPubRateLimiter, | ||
9 | asyncMiddleware, | ||
10 | checkSignature, | ||
11 | ensureIsLocalChannel, | ||
12 | localAccountValidator, | ||
13 | signatureValidator, | ||
14 | videoChannelsNameWithHostValidator | ||
15 | } from '../../middlewares' | ||
16 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | ||
17 | |||
18 | const inboxRouter = express.Router() | ||
19 | |||
20 | inboxRouter.post('/inbox', | ||
21 | activityPubRateLimiter, | ||
22 | signatureValidator, | ||
23 | asyncMiddleware(checkSignature), | ||
24 | asyncMiddleware(activityPubValidator), | ||
25 | inboxController | ||
26 | ) | ||
27 | |||
28 | inboxRouter.post('/accounts/:name/inbox', | ||
29 | activityPubRateLimiter, | ||
30 | signatureValidator, | ||
31 | asyncMiddleware(checkSignature), | ||
32 | asyncMiddleware(localAccountValidator), | ||
33 | asyncMiddleware(activityPubValidator), | ||
34 | inboxController | ||
35 | ) | ||
36 | |||
37 | inboxRouter.post('/video-channels/:nameWithHost/inbox', | ||
38 | activityPubRateLimiter, | ||
39 | signatureValidator, | ||
40 | asyncMiddleware(checkSignature), | ||
41 | asyncMiddleware(videoChannelsNameWithHostValidator), | ||
42 | ensureIsLocalChannel, | ||
43 | asyncMiddleware(activityPubValidator), | ||
44 | inboxController | ||
45 | ) | ||
46 | |||
47 | // --------------------------------------------------------------------------- | ||
48 | |||
49 | export { | ||
50 | inboxRouter | ||
51 | } | ||
52 | |||
53 | // --------------------------------------------------------------------------- | ||
54 | |||
55 | function inboxController (req: express.Request, res: express.Response) { | ||
56 | const rootActivity: RootActivity = req.body | ||
57 | let activities: Activity[] | ||
58 | |||
59 | if ([ 'Collection', 'CollectionPage' ].includes(rootActivity.type)) { | ||
60 | activities = (rootActivity as ActivityPubCollection).items | ||
61 | } else if ([ 'OrderedCollection', 'OrderedCollectionPage' ].includes(rootActivity.type)) { | ||
62 | activities = (rootActivity as ActivityPubOrderedCollection<Activity>).orderedItems | ||
63 | } else { | ||
64 | activities = [ rootActivity as Activity ] | ||
65 | } | ||
66 | |||
67 | // Only keep activities we are able to process | ||
68 | logger.debug('Filtering %d activities...', activities.length) | ||
69 | activities = activities.filter(a => isActivityValid(a)) | ||
70 | logger.debug('We keep %d activities.', activities.length, { activities }) | ||
71 | |||
72 | const accountOrChannel = res.locals.account || res.locals.videoChannel | ||
73 | |||
74 | logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url) | ||
75 | |||
76 | InboxManager.Instance.addInboxMessage({ | ||
77 | activities, | ||
78 | signatureActor: res.locals.signature.actor, | ||
79 | inboxActor: accountOrChannel | ||
80 | ? accountOrChannel.Actor | ||
81 | : undefined | ||
82 | }) | ||
83 | |||
84 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | ||
85 | } | ||