aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/actor.ts
blob: da7f2eb910c24db6f8579de69c2cc220dcaa3211 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as express from 'express'
import { JobQueue } from '../../lib/job-queue'
import { asyncMiddleware } from '../../middlewares'
import { actorNameWithHostGetValidator } from '../../middlewares/validators'

const actorRouter = express.Router()

actorRouter.get('/:actorName',
  asyncMiddleware(actorNameWithHostGetValidator),
  getActor
)

// ---------------------------------------------------------------------------

export {
  actorRouter
}

// ---------------------------------------------------------------------------

function getActor (req: express.Request, res: express.Response) {
  let accountOrVideoChannel

  if (res.locals.account) {
    accountOrVideoChannel = res.locals.account
  }

  if (res.locals.videoChannel) {
    accountOrVideoChannel = res.locals.videoChannel
  }

  if (accountOrVideoChannel.isOutdated()) {
    JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: accountOrVideoChannel.Actor.url } })
  }

  return res.json(accountOrVideoChannel.toFormattedJSON())
}