1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Add server API actors route

This commit is contained in:
Kimsible 2021-04-28 17:33:55 +02:00
parent ff8c5ccf09
commit 1e37d32f4b
6 changed files with 120 additions and 9 deletions

View file

@ -0,0 +1,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())
}

View file

@ -15,6 +15,7 @@ import { pluginRouter } from './plugins'
import { searchRouter } from './search'
import { serverRouter } from './server'
import { usersRouter } from './users'
import { actorRouter } from './actor'
import { videoChannelRouter } from './video-channel'
import { videoPlaylistRouter } from './video-playlist'
import { videosRouter } from './videos'
@ -39,6 +40,7 @@ apiRouter.use('/bulk', bulkRouter)
apiRouter.use('/oauth-clients', oauthClientsRouter)
apiRouter.use('/config', configRouter)
apiRouter.use('/users', usersRouter)
apiRouter.use('/actors', actorRouter)
apiRouter.use('/accounts', accountsRouter)
apiRouter.use('/video-channels', videoChannelRouter)
apiRouter.use('/video-playlists', videoPlaylistRouter)