Add subscriptions endpoints to REST API
This commit is contained in:
parent
4bda2e47bb
commit
06a05d5f47
36 changed files with 1039 additions and 94 deletions
|
@ -3,9 +3,10 @@ import { Activity, ActivityPubCollection, ActivityPubOrderedCollection, RootActi
|
|||
import { isActivityValid } from '../../helpers/custom-validators/activitypub/activity'
|
||||
import { logger } from '../../helpers/logger'
|
||||
import { processActivities } from '../../lib/activitypub/process/process'
|
||||
import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares'
|
||||
import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChannelValidator, signatureValidator } from '../../middlewares'
|
||||
import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
|
||||
import { ActorModel } from '../../models/activitypub/actor'
|
||||
import { VideoChannelModel } from '../../models/video/video-channel'
|
||||
import { AccountModel } from '../../models/account/account'
|
||||
|
||||
const inboxRouter = express.Router()
|
||||
|
||||
|
@ -23,6 +24,13 @@ inboxRouter.post('/accounts/:name/inbox',
|
|||
asyncMiddleware(activityPubValidator),
|
||||
asyncMiddleware(inboxController)
|
||||
)
|
||||
inboxRouter.post('/video-channels/:name/inbox',
|
||||
signatureValidator,
|
||||
asyncMiddleware(checkSignature),
|
||||
asyncMiddleware(localVideoChannelValidator),
|
||||
asyncMiddleware(activityPubValidator),
|
||||
asyncMiddleware(inboxController)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
@ -49,16 +57,16 @@ async function inboxController (req: express.Request, res: express.Response, nex
|
|||
activities = activities.filter(a => isActivityValid(a))
|
||||
logger.debug('We keep %d activities.', activities.length, { activities })
|
||||
|
||||
let specificActor: ActorModel = undefined
|
||||
let accountOrChannel: VideoChannelModel | AccountModel
|
||||
if (res.locals.account) {
|
||||
specificActor = res.locals.account
|
||||
accountOrChannel = res.locals.account
|
||||
} else if (res.locals.videoChannel) {
|
||||
specificActor = res.locals.videoChannel
|
||||
accountOrChannel = res.locals.videoChannel
|
||||
}
|
||||
|
||||
logger.info('Receiving inbox requests for %d activities by %s.', activities.length, res.locals.signature.actor.url)
|
||||
|
||||
await processActivities(activities, res.locals.signature.actor, specificActor)
|
||||
await processActivities(activities, res.locals.signature.actor, accountOrChannel ? accountOrChannel.Actor : undefined)
|
||||
|
||||
res.status(204).end()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue