]>
Commit | Line | Data |
---|---|---|
1 | import * as express from 'express' | |
2 | import { Activity } from '../../../shared/models/activitypub/activity' | |
3 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | |
4 | import { pageToStartAndCount } from '../../helpers/core-utils' | |
5 | import { ACTIVITY_PUB } from '../../initializers/constants' | |
6 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' | |
7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | |
8 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | |
9 | import { AccountModel } from '../../models/account/account' | |
10 | import { VideoModel } from '../../models/video/video' | |
11 | ||
12 | const outboxRouter = express.Router() | |
13 | ||
14 | outboxRouter.get('/accounts/:name/outbox', | |
15 | localAccountValidator, | |
16 | asyncMiddleware(outboxController) | |
17 | ) | |
18 | ||
19 | // --------------------------------------------------------------------------- | |
20 | ||
21 | export { | |
22 | outboxRouter | |
23 | } | |
24 | ||
25 | // --------------------------------------------------------------------------- | |
26 | ||
27 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | |
28 | const account: AccountModel = res.locals.account | |
29 | const actor = account.Actor | |
30 | ||
31 | const page = req.query.page || 1 | |
32 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | |
33 | ||
34 | const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count) | |
35 | const activities: Activity[] = [] | |
36 | ||
37 | for (const video of data.data) { | |
38 | const videoObject = video.toActivityPubObject() | |
39 | ||
40 | const videoChannel = video.VideoChannel | |
41 | // This is a shared video | |
42 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { | |
43 | const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) | |
44 | ||
45 | const url = getAnnounceActivityPubUrl(video.url, actor) | |
46 | const announceActivity = await announceActivityData(url, actor, createActivity, undefined) | |
47 | ||
48 | activities.push(announceActivity) | |
49 | } else { | |
50 | const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) | |
51 | ||
52 | activities.push(createActivity) | |
53 | } | |
54 | } | |
55 | ||
56 | const newResult = { | |
57 | data: activities, | |
58 | total: data.total | |
59 | } | |
60 | const json = activityPubCollectionPagination(account.Actor.url + '/outbox', page, newResult) | |
61 | ||
62 | return res.json(json).end() | |
63 | } |