aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-21 18:23:10 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commite71bcc0f4b31ecfd84a786411febfc6d18a85258 (patch)
treeea31776b6bc69bd3b72e6c6f615cf94072271c82 /server/controllers
parentb1cbc0dd3ee0fce6d8390b6d3996386a5b6097ac (diff)
downloadPeerTube-e71bcc0f4b31ecfd84a786411febfc6d18a85258.tar.gz
PeerTube-e71bcc0f4b31ecfd84a786411febfc6d18a85258.tar.zst
PeerTube-e71bcc0f4b31ecfd84a786411febfc6d18a85258.zip
Add outbox
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/client.ts6
-rw-r--r--server/controllers/activitypub/index.ts2
-rw-r--r--server/controllers/activitypub/outbox.ts60
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'
6import { pageToStartAndCount } from '../../helpers' 6import { pageToStartAndCount } from '../../helpers'
7import { AccountInstance, VideoChannelInstance } from '../../models' 7import { AccountInstance, VideoChannelInstance } from '../../models'
8import { activityPubCollectionPagination } from '../../helpers/activitypub' 8import { activityPubCollectionPagination } from '../../helpers/activitypub'
9import { ACTIVITY_PUB } from '../../initializers/constants' 9import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants'
10import { asyncMiddleware } from '../../middlewares/async' 10import { asyncMiddleware } from '../../middlewares/async'
11import { videosGetValidator } from '../../middlewares/validators/videos' 11import { videosGetValidator } from '../../middlewares/validators/videos'
12import { VideoInstance } from '../../models/video/video-interface' 12import { 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { activityPubClientRouter } from './client' 2import { activityPubClientRouter } from './client'
3import { inboxRouter } from './inbox' 3import { inboxRouter } from './inbox'
4import { outboxRouter } from './outbox'
4 5
5const activityPubRouter = express.Router() 6const activityPubRouter = express.Router()
6 7
7activityPubRouter.use('/', inboxRouter) 8activityPubRouter.use('/', inboxRouter)
9activityPubRouter.use('/', outboxRouter)
8activityPubRouter.use('/', activityPubClientRouter) 10activityPubRouter.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 @@
1import * as express from 'express'
2import { Activity, ActivityAdd } from '../../../shared/models/activitypub/activity'
3import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
4import { database as db } from '../../initializers'
5import { addActivityData } from '../../lib/activitypub/send/send-add'
6import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
7import { announceActivityData } from '../../lib/index'
8import { asyncMiddleware, localAccountValidator } from '../../middlewares'
9import { AccountInstance } from '../../models/account/account-interface'
10import { pageToStartAndCount } from '../../helpers/core-utils'
11import { ACTIVITY_PUB } from '../../initializers/constants'
12
13const outboxRouter = express.Router()
14
15outboxRouter.get('/account/:name/outbox',
16 localAccountValidator,
17 asyncMiddleware(outboxController)
18)
19
20// ---------------------------------------------------------------------------
21
22export {
23 outboxRouter
24}
25
26// ---------------------------------------------------------------------------
27
28async 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}