diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 6 | ||||
-rw-r--r-- | server/controllers/activitypub/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 60 |
3 files changed, 65 insertions, 3 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 7b3921770..24c8665a5 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -6,7 +6,7 @@ import { executeIfActivityPub, localAccountValidator } from '../../middlewares' | |||
6 | import { pageToStartAndCount } from '../../helpers' | 6 | import { pageToStartAndCount } from '../../helpers' |
7 | import { AccountInstance, VideoChannelInstance } from '../../models' | 7 | import { AccountInstance, VideoChannelInstance } from '../../models' |
8 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | 8 | import { activityPubCollectionPagination } from '../../helpers/activitypub' |
9 | import { ACTIVITY_PUB } from '../../initializers/constants' | 9 | import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants' |
10 | import { asyncMiddleware } from '../../middlewares/async' | 10 | import { asyncMiddleware } from '../../middlewares/async' |
11 | import { videosGetValidator } from '../../middlewares/validators/videos' | 11 | import { videosGetValidator } from '../../middlewares/validators/videos' |
12 | import { VideoInstance } from '../../models/video/video-interface' | 12 | import { VideoInstance } from '../../models/video/video-interface' |
@@ -60,7 +60,7 @@ async function accountFollowersController (req: express.Request, res: express.Re | |||
60 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 60 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
61 | 61 | ||
62 | const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], start, count) | 62 | const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], start, count) |
63 | const activityPubResult = activityPubCollectionPagination(req.url, page, result) | 63 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
64 | 64 | ||
65 | return res.json(activityPubResult) | 65 | return res.json(activityPubResult) |
66 | } | 66 | } |
@@ -72,7 +72,7 @@ async function accountFollowingController (req: express.Request, res: express.Re | |||
72 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 72 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
73 | 73 | ||
74 | const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], start, count) | 74 | const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], start, count) |
75 | const activityPubResult = activityPubCollectionPagination(req.url, page, result) | 75 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
76 | 76 | ||
77 | return res.json(activityPubResult) | 77 | return res.json(activityPubResult) |
78 | } | 78 | } |
diff --git a/server/controllers/activitypub/index.ts b/server/controllers/activitypub/index.ts index c5bec6448..7e81902af 100644 --- a/server/controllers/activitypub/index.ts +++ b/server/controllers/activitypub/index.ts | |||
@@ -1,10 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { activityPubClientRouter } from './client' | 2 | import { activityPubClientRouter } from './client' |
3 | import { inboxRouter } from './inbox' | 3 | import { inboxRouter } from './inbox' |
4 | import { outboxRouter } from './outbox' | ||
4 | 5 | ||
5 | const activityPubRouter = express.Router() | 6 | const activityPubRouter = express.Router() |
6 | 7 | ||
7 | activityPubRouter.use('/', inboxRouter) | 8 | activityPubRouter.use('/', inboxRouter) |
9 | activityPubRouter.use('/', outboxRouter) | ||
8 | activityPubRouter.use('/', activityPubClientRouter) | 10 | activityPubRouter.use('/', activityPubClientRouter) |
9 | 11 | ||
10 | // --------------------------------------------------------------------------- | 12 | // --------------------------------------------------------------------------- |
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts new file mode 100644 index 000000000..396fa2db5 --- /dev/null +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -0,0 +1,60 @@ | |||
1 | import * as express from 'express' | ||
2 | import { Activity, ActivityAdd } from '../../../shared/models/activitypub/activity' | ||
3 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | ||
4 | import { database as db } from '../../initializers' | ||
5 | import { addActivityData } from '../../lib/activitypub/send/send-add' | ||
6 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | ||
7 | import { announceActivityData } from '../../lib/index' | ||
8 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | ||
9 | import { AccountInstance } from '../../models/account/account-interface' | ||
10 | import { pageToStartAndCount } from '../../helpers/core-utils' | ||
11 | import { ACTIVITY_PUB } from '../../initializers/constants' | ||
12 | |||
13 | const outboxRouter = express.Router() | ||
14 | |||
15 | outboxRouter.get('/account/:name/outbox', | ||
16 | localAccountValidator, | ||
17 | asyncMiddleware(outboxController) | ||
18 | ) | ||
19 | |||
20 | // --------------------------------------------------------------------------- | ||
21 | |||
22 | export { | ||
23 | outboxRouter | ||
24 | } | ||
25 | |||
26 | // --------------------------------------------------------------------------- | ||
27 | |||
28 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
29 | const account: AccountInstance = res.locals.account | ||
30 | |||
31 | const page = req.params.page || 1 | ||
32 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | ||
33 | |||
34 | const data = await db.Video.listAllAndSharedByAccountForOutbox(account.id, start, count) | ||
35 | const activities: Activity[] = [] | ||
36 | |||
37 | console.log(account.url) | ||
38 | |||
39 | for (const video of data.data) { | ||
40 | const videoObject = video.toActivityPubObject() | ||
41 | let addActivity: ActivityAdd = await addActivityData(video.url, account, video, video.VideoChannel.url, videoObject) | ||
42 | |||
43 | // This is a shared video | ||
44 | if (video.VideoShare !== undefined) { | ||
45 | const url = getAnnounceActivityPubUrl(video.url, account) | ||
46 | const announceActivity = await announceActivityData(url, account, addActivity) | ||
47 | activities.push(announceActivity) | ||
48 | } else { | ||
49 | activities.push(addActivity) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | const newResult = { | ||
54 | data: activities, | ||
55 | total: data.total | ||
56 | } | ||
57 | const json = activityPubCollectionPagination(account.url + '/outbox', page, newResult) | ||
58 | |||
59 | return res.json(json).end() | ||
60 | } | ||