diff options
author | Kimsible <kimsible@users.noreply.github.com> | 2021-04-28 17:33:55 +0200 |
---|---|---|
committer | Kimsible <kimsible@users.noreply.github.com> | 2021-05-05 11:47:03 +0200 |
commit | 1e37d32f4bdc51045cd85d01ea1035fd53e0d32c (patch) | |
tree | 2e7bcf053989fc5be9e3ef29558cf1fcf32f8453 /server/controllers/api/actor.ts | |
parent | ff8c5ccf09cfe6a469777d4789625f8fdb004408 (diff) | |
download | PeerTube-1e37d32f4bdc51045cd85d01ea1035fd53e0d32c.tar.gz PeerTube-1e37d32f4bdc51045cd85d01ea1035fd53e0d32c.tar.zst PeerTube-1e37d32f4bdc51045cd85d01ea1035fd53e0d32c.zip |
Add server API actors route
Diffstat (limited to 'server/controllers/api/actor.ts')
-rw-r--r-- | server/controllers/api/actor.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/server/controllers/api/actor.ts b/server/controllers/api/actor.ts new file mode 100644 index 000000000..da7f2eb91 --- /dev/null +++ b/server/controllers/api/actor.ts | |||
@@ -0,0 +1,37 @@ | |||
1 | import * as express from 'express' | ||
2 | import { JobQueue } from '../../lib/job-queue' | ||
3 | import { asyncMiddleware } from '../../middlewares' | ||
4 | import { actorNameWithHostGetValidator } from '../../middlewares/validators' | ||
5 | |||
6 | const actorRouter = express.Router() | ||
7 | |||
8 | actorRouter.get('/:actorName', | ||
9 | asyncMiddleware(actorNameWithHostGetValidator), | ||
10 | getActor | ||
11 | ) | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | export { | ||
16 | actorRouter | ||
17 | } | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | function 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 | } | ||