diff options
Diffstat (limited to 'server/controllers/activitypub/outbox.ts')
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts deleted file mode 100644 index 8c88b6971..000000000 --- a/server/controllers/activitypub/outbox.ts +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { activityPubCollectionPagination } from '@server/lib/activitypub/collection' | ||
3 | import { activityPubContextify } from '@server/lib/activitypub/context' | ||
4 | import { MActorLight } from '@server/types/models' | ||
5 | import { Activity } from '../../../shared/models/activitypub/activity' | ||
6 | import { VideoPrivacy } from '../../../shared/models/videos' | ||
7 | import { logger } from '../../helpers/logger' | ||
8 | import { buildAudience } from '../../lib/activitypub/audience' | ||
9 | import { buildAnnounceActivity, buildCreateActivity } from '../../lib/activitypub/send' | ||
10 | import { | ||
11 | activityPubRateLimiter, | ||
12 | asyncMiddleware, | ||
13 | ensureIsLocalChannel, | ||
14 | localAccountValidator, | ||
15 | videoChannelsNameWithHostValidator | ||
16 | } from '../../middlewares' | ||
17 | import { apPaginationValidator } from '../../middlewares/validators/activitypub' | ||
18 | import { VideoModel } from '../../models/video/video' | ||
19 | import { activityPubResponse } from './utils' | ||
20 | |||
21 | const outboxRouter = express.Router() | ||
22 | |||
23 | outboxRouter.get('/accounts/:name/outbox', | ||
24 | activityPubRateLimiter, | ||
25 | apPaginationValidator, | ||
26 | localAccountValidator, | ||
27 | asyncMiddleware(outboxController) | ||
28 | ) | ||
29 | |||
30 | outboxRouter.get('/video-channels/:nameWithHost/outbox', | ||
31 | activityPubRateLimiter, | ||
32 | apPaginationValidator, | ||
33 | asyncMiddleware(videoChannelsNameWithHostValidator), | ||
34 | ensureIsLocalChannel, | ||
35 | asyncMiddleware(outboxController) | ||
36 | ) | ||
37 | |||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | export { | ||
41 | outboxRouter | ||
42 | } | ||
43 | |||
44 | // --------------------------------------------------------------------------- | ||
45 | |||
46 | async function outboxController (req: express.Request, res: express.Response) { | ||
47 | const accountOrVideoChannel = res.locals.account || res.locals.videoChannel | ||
48 | const actor = accountOrVideoChannel.Actor | ||
49 | const actorOutboxUrl = actor.url + '/outbox' | ||
50 | |||
51 | logger.info('Receiving outbox request for %s.', actorOutboxUrl) | ||
52 | |||
53 | const handler = (start: number, count: number) => buildActivities(actor, start, count) | ||
54 | const json = await activityPubCollectionPagination(actorOutboxUrl, handler, req.query.page, req.query.size) | ||
55 | |||
56 | return activityPubResponse(activityPubContextify(json, 'Collection'), res) | ||
57 | } | ||
58 | |||
59 | async function buildActivities (actor: MActorLight, start: number, count: number) { | ||
60 | const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count) | ||
61 | const activities: Activity[] = [] | ||
62 | |||
63 | for (const video of data.data) { | ||
64 | const byActor = video.VideoChannel.Account.Actor | ||
65 | const createActivityAudience = buildAudience([ byActor.followersUrl ], video.privacy === VideoPrivacy.PUBLIC) | ||
66 | |||
67 | // This is a shared video | ||
68 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { | ||
69 | const videoShare = video.VideoShares[0] | ||
70 | const announceActivity = buildAnnounceActivity(videoShare.url, actor, video.url, createActivityAudience) | ||
71 | |||
72 | activities.push(announceActivity) | ||
73 | } else { | ||
74 | // FIXME: only use the video URL to reduce load. Breaks compat with PeerTube < 6.0.0 | ||
75 | const videoObject = await video.toActivityPubObject() | ||
76 | const createActivity = buildCreateActivity(video.url, byActor, videoObject, createActivityAudience) | ||
77 | |||
78 | activities.push(createActivity) | ||
79 | } | ||
80 | } | ||
81 | |||
82 | return { | ||
83 | data: activities, | ||
84 | total: data.total | ||
85 | } | ||
86 | } | ||