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()
asyncMiddleware(outboxController)
)
+outboxRouter.get('/video-channels/:name/outbox',
+ localVideoChannelValidator,
+ asyncMiddleware(outboxController)
+)
+
// ---------------------------------------------------------------------------
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)
const actors = data.data.map(v => v.VideoChannel.Account.Actor)
actors.push(actor)
- const followersMatrix = await ActorModel.getActorsFollowerSharedInboxUrls(actors, undefined)
-
for (const video of data.data) {
const byActor = video.VideoChannel.Account.Actor
- const createActivityAudience = buildAudience(followersMatrix[byActor.id], video.privacy === VideoPrivacy.PUBLIC)
+ const createActivityAudience = buildAudience([ byActor.followersUrl ], video.privacy === VideoPrivacy.PUBLIC)
// This is a shared video
if (video.VideoShares !== undefined && video.VideoShares.length !== 0) {
const videoShare = video.VideoShares[0]
- const announceAudience = buildAudience(followersMatrix[actor.id], video.privacy === VideoPrivacy.PUBLIC)
- const announceActivity = await announceActivityData(videoShare.url, actor, video.url, undefined, announceAudience)
+ const announceActivity = announceActivityData(videoShare.url, actor, video.url, createActivityAudience)
activities.push(announceActivity)
} else {
const videoObject = video.toActivityPubObject()
- const createActivity = await createActivityData(video.url, byActor, videoObject, undefined, createActivityAudience)
+ const createActivity = createActivityData(video.url, byActor, videoObject, createActivityAudience)
activities.push(createActivity)
}