2017-11-09 10:51:58 -06:00
|
|
|
// Intercept ActivityPub client requests
|
|
|
|
import * as express from 'express'
|
|
|
|
|
|
|
|
import { database as db } from '../../initializers'
|
|
|
|
import { executeIfActivityPub, localAccountValidator } from '../../middlewares'
|
|
|
|
import { pageToStartAndCount } from '../../helpers'
|
|
|
|
import { AccountInstance } from '../../models'
|
|
|
|
import { activityPubCollectionPagination } from '../../helpers/activitypub'
|
|
|
|
import { ACTIVITY_PUB } from '../../initializers/constants'
|
|
|
|
import { asyncMiddleware } from '../../middlewares/async'
|
|
|
|
|
|
|
|
const activityPubClientRouter = express.Router()
|
|
|
|
|
|
|
|
activityPubClientRouter.get('/account/:name',
|
|
|
|
executeIfActivityPub(localAccountValidator),
|
|
|
|
executeIfActivityPub(asyncMiddleware(accountController))
|
|
|
|
)
|
|
|
|
|
2017-11-14 10:31:26 -06:00
|
|
|
activityPubClientRouter.get('/account/:name/followers',
|
2017-11-09 10:51:58 -06:00
|
|
|
executeIfActivityPub(localAccountValidator),
|
|
|
|
executeIfActivityPub(asyncMiddleware(accountFollowersController))
|
|
|
|
)
|
|
|
|
|
2017-11-14 10:31:26 -06:00
|
|
|
activityPubClientRouter.get('/account/:name/following',
|
2017-11-09 10:51:58 -06:00
|
|
|
executeIfActivityPub(localAccountValidator),
|
|
|
|
executeIfActivityPub(asyncMiddleware(accountFollowingController))
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
activityPubClientRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function accountController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
|
|
const account: AccountInstance = res.locals.account
|
|
|
|
|
|
|
|
return res.json(account.toActivityPubObject()).end()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
|
|
const account: AccountInstance = res.locals.account
|
|
|
|
|
|
|
|
const page = req.params.page || 1
|
|
|
|
const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
|
|
|
|
|
2017-11-16 04:08:25 -06:00
|
|
|
const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], start, count)
|
2017-11-09 10:51:58 -06:00
|
|
|
const activityPubResult = activityPubCollectionPagination(req.url, page, result)
|
|
|
|
|
|
|
|
return res.json(activityPubResult)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
|
|
const account: AccountInstance = res.locals.account
|
|
|
|
|
|
|
|
const page = req.params.page || 1
|
|
|
|
const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
|
|
|
|
|
2017-11-16 04:08:25 -06:00
|
|
|
const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], start, count)
|
2017-11-09 10:51:58 -06:00
|
|
|
const activityPubResult = activityPubCollectionPagination(req.url, page, result)
|
|
|
|
|
|
|
|
return res.json(activityPubResult)
|
|
|
|
}
|