]>
Commit | Line | Data |
---|---|---|
e71bcc0f | 1 | import * as express from 'express' |
d52eb8f6 | 2 | import { Activity } from '../../../shared/models/activitypub/activity' |
0bc22f8d | 3 | import { VideoPrivacy } from '../../../shared/models/videos' |
8fffe21a | 4 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' |
0a8ae684 | 5 | import { logger } from '../../helpers/logger' |
c48e82b5 | 6 | import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send' |
e251f170 | 7 | import { buildAudience } from '../../lib/activitypub/audience' |
06a05d5f | 8 | import { asyncMiddleware, localAccountValidator, localVideoChannelValidator } from '../../middlewares' |
3fd3ab2d | 9 | import { VideoModel } from '../../models/video/video' |
8fffe21a | 10 | import { activityPubResponse } from './utils' |
453e83ea | 11 | import { MActorLight } from '@server/typings/models' |
e71bcc0f C |
12 | |
13 | const outboxRouter = express.Router() | |
14 | ||
e8e12200 | 15 | outboxRouter.get('/accounts/:name/outbox', |
e71bcc0f C |
16 | localAccountValidator, |
17 | asyncMiddleware(outboxController) | |
18 | ) | |
19 | ||
06a05d5f C |
20 | outboxRouter.get('/video-channels/:name/outbox', |
21 | localVideoChannelValidator, | |
22 | asyncMiddleware(outboxController) | |
23 | ) | |
24 | ||
e71bcc0f C |
25 | // --------------------------------------------------------------------------- |
26 | ||
27 | export { | |
28 | outboxRouter | |
29 | } | |
30 | ||
31 | // --------------------------------------------------------------------------- | |
32 | ||
418d092a | 33 | async function outboxController (req: express.Request, res: express.Response) { |
dae86118 | 34 | const accountOrVideoChannel = res.locals.account || res.locals.videoChannel |
06a05d5f C |
35 | const actor = accountOrVideoChannel.Actor |
36 | const actorOutboxUrl = actor.url + '/outbox' | |
8fffe21a C |
37 | |
38 | logger.info('Receiving outbox request for %s.', actorOutboxUrl) | |
e71bcc0f | 39 | |
8fffe21a C |
40 | const handler = (start: number, count: number) => buildActivities(actor, start, count) |
41 | const json = await activityPubCollectionPagination(actorOutboxUrl, handler, req.query.page) | |
42 | ||
43 | return activityPubResponse(activityPubContextify(json), res) | |
44 | } | |
e71bcc0f | 45 | |
453e83ea | 46 | async function buildActivities (actor: MActorLight, start: number, count: number) { |
50d6de9c | 47 | const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count) |
e71bcc0f C |
48 | const activities: Activity[] = [] |
49 | ||
e71bcc0f | 50 | for (const video of data.data) { |
54e74059 | 51 | const byActor = video.VideoChannel.Account.Actor |
e3d5ea4f | 52 | const createActivityAudience = buildAudience([ byActor.followersUrl ], video.privacy === VideoPrivacy.PUBLIC) |
54e74059 | 53 | |
50d6de9c | 54 | // This is a shared video |
40ff5707 | 55 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { |
4ba3b8ea | 56 | const videoShare = video.VideoShares[0] |
c48e82b5 | 57 | const announceActivity = buildAnnounceActivity(videoShare.url, actor, video.url, createActivityAudience) |
40ff5707 | 58 | |
e71bcc0f C |
59 | activities.push(announceActivity) |
60 | } else { | |
7acee6f1 | 61 | const videoObject = video.toActivityPubObject() |
c48e82b5 | 62 | const createActivity = buildCreateActivity(video.url, byActor, videoObject, createActivityAudience) |
40ff5707 | 63 | |
50d6de9c | 64 | activities.push(createActivity) |
e71bcc0f C |
65 | } |
66 | } | |
67 | ||
8fffe21a | 68 | return { |
e71bcc0f C |
69 | data: activities, |
70 | total: data.total | |
71 | } | |
e71bcc0f | 72 | } |