aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub/client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/activitypub/client.ts')
-rw-r--r--server/controllers/activitypub/client.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
new file mode 100644
index 000000000..28d08b3f4
--- /dev/null
+++ b/server/controllers/activitypub/client.ts
@@ -0,0 +1,65 @@
1// Intercept ActivityPub client requests
2import * as express from 'express'
3
4import { database as db } from '../../initializers'
5import { executeIfActivityPub, localAccountValidator } from '../../middlewares'
6import { pageToStartAndCount } from '../../helpers'
7import { AccountInstance } from '../../models'
8import { activityPubCollectionPagination } from '../../helpers/activitypub'
9import { ACTIVITY_PUB } from '../../initializers/constants'
10import { asyncMiddleware } from '../../middlewares/async'
11
12const activityPubClientRouter = express.Router()
13
14activityPubClientRouter.get('/account/:name',
15 executeIfActivityPub(localAccountValidator),
16 executeIfActivityPub(asyncMiddleware(accountController))
17)
18
19activityPubClientRouter.get('/account/:name/followers',
20 executeIfActivityPub(localAccountValidator),
21 executeIfActivityPub(asyncMiddleware(accountFollowersController))
22)
23
24activityPubClientRouter.get('/account/:name/following',
25 executeIfActivityPub(localAccountValidator),
26 executeIfActivityPub(asyncMiddleware(accountFollowingController))
27)
28
29// ---------------------------------------------------------------------------
30
31export {
32 activityPubClientRouter
33}
34
35// ---------------------------------------------------------------------------
36
37async function accountController (req: express.Request, res: express.Response, next: express.NextFunction) {
38 const account: AccountInstance = res.locals.account
39
40 return res.json(account.toActivityPubObject()).end()
41}
42
43async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
44 const account: AccountInstance = res.locals.account
45
46 const page = req.params.page || 1
47 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
48
49 const result = await db.Account.listFollowerUrlsForApi(account.name, start, count)
50 const activityPubResult = activityPubCollectionPagination(req.url, page, result)
51
52 return res.json(activityPubResult)
53}
54
55async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
56 const account: AccountInstance = res.locals.account
57
58 const page = req.params.page || 1
59 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
60
61 const result = await db.Account.listFollowingUrlsForApi(account.name, start, count)
62 const activityPubResult = activityPubCollectionPagination(req.url, page, result)
63
64 return res.json(activityPubResult)
65}