]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/actor.ts
Add server API actors route
[github/Chocobozzz/PeerTube.git] / server / controllers / api / actor.ts
CommitLineData
1e37d32f
K
1import * as express from 'express'
2import { JobQueue } from '../../lib/job-queue'
3import { asyncMiddleware } from '../../middlewares'
4import { actorNameWithHostGetValidator } from '../../middlewares/validators'
5
6const actorRouter = express.Router()
7
8actorRouter.get('/:actorName',
9 asyncMiddleware(actorNameWithHostGetValidator),
10 getActor
11)
12
13// ---------------------------------------------------------------------------
14
15export {
16 actorRouter
17}
18
19// ---------------------------------------------------------------------------
20
21function getActor (req: express.Request, res: express.Response) {
22 let accountOrVideoChannel
23
24 if (res.locals.account) {
25 accountOrVideoChannel = res.locals.account
26 }
27
28 if (res.locals.videoChannel) {
29 accountOrVideoChannel = res.locals.videoChannel
30 }
31
32 if (accountOrVideoChannel.isOutdated()) {
33 JobQueue.Instance.createJob({ type: 'activitypub-refresher', payload: { type: 'actor', url: accountOrVideoChannel.Actor.url } })
34 }
35
36 return res.json(accountOrVideoChannel.toFormattedJSON())
37}