diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/actor.ts | 37 | ||||
-rw-r--r-- | server/controllers/api/index.ts | 2 |
2 files changed, 39 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 | } | ||
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 7ade1df3a..4f4561ffd 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -15,6 +15,7 @@ import { pluginRouter } from './plugins' | |||
15 | import { searchRouter } from './search' | 15 | import { searchRouter } from './search' |
16 | import { serverRouter } from './server' | 16 | import { serverRouter } from './server' |
17 | import { usersRouter } from './users' | 17 | import { usersRouter } from './users' |
18 | import { actorRouter } from './actor' | ||
18 | import { videoChannelRouter } from './video-channel' | 19 | import { videoChannelRouter } from './video-channel' |
19 | import { videoPlaylistRouter } from './video-playlist' | 20 | import { videoPlaylistRouter } from './video-playlist' |
20 | import { videosRouter } from './videos' | 21 | import { videosRouter } from './videos' |
@@ -39,6 +40,7 @@ apiRouter.use('/bulk', bulkRouter) | |||
39 | apiRouter.use('/oauth-clients', oauthClientsRouter) | 40 | apiRouter.use('/oauth-clients', oauthClientsRouter) |
40 | apiRouter.use('/config', configRouter) | 41 | apiRouter.use('/config', configRouter) |
41 | apiRouter.use('/users', usersRouter) | 42 | apiRouter.use('/users', usersRouter) |
43 | apiRouter.use('/actors', actorRouter) | ||
42 | apiRouter.use('/accounts', accountsRouter) | 44 | apiRouter.use('/accounts', accountsRouter) |
43 | apiRouter.use('/video-channels', videoChannelRouter) | 45 | apiRouter.use('/video-channels', videoChannelRouter) |
44 | apiRouter.use('/video-playlists', videoPlaylistRouter) | 46 | apiRouter.use('/video-playlists', videoPlaylistRouter) |