1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

Add subscriptions endpoints to REST API

This commit is contained in:
Chocobozzz 2018-08-16 15:25:20 +02:00
parent 4bda2e47bb
commit 06a05d5f47
36 changed files with 1039 additions and 94 deletions

View file

@ -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()
}

View file

@ -5,11 +5,12 @@ import { activityPubCollectionPagination, activityPubContextify } from '../../he
import { logger } from '../../helpers/logger'
import { announceActivityData, createActivityData } from '../../lib/activitypub/send'
import { buildAudience } from '../../lib/activitypub/audience'
import { asyncMiddleware, localAccountValidator } from '../../middlewares'
import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares'
import { AccountModel } from '../../models/account/account'
import { ActorModel } from '../../models/activitypub/actor'
import { VideoModel } from '../../models/video/video'
import { activityPubResponse } from './utils'
import { VideoChannelModel } from '../../models/video/video-channel'
const outboxRouter = express.Router()
@ -18,6 +19,11 @@ outboxRouter.get('/accounts/:name/outbox',
asyncMiddleware(outboxController)
)
outboxRouter.get('/video-channels/:name/outbox',
localVideoChannelValidator,
asyncMiddleware(outboxController)
)
// ---------------------------------------------------------------------------
export {
@ -27,9 +33,9 @@ export {
// ---------------------------------------------------------------------------
async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) {
const account: AccountModel = res.locals.account
const actor = account.Actor
const actorOutboxUrl = account.Actor.url + '/outbox'
const accountOrVideoChannel: AccountModel | VideoChannelModel = res.locals.account || res.locals.videoChannel
const actor = accountOrVideoChannel.Actor
const actorOutboxUrl = actor.url + '/outbox'
logger.info('Receiving outbox request for %s.', actorOutboxUrl)