aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r--server/controllers/activitypub/client.ts48
-rw-r--r--server/controllers/activitypub/outbox.ts8
2 files changed, 29 insertions, 27 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index a478acd14..72b216254 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -1,20 +1,22 @@
1// Intercept ActivityPub client requests 1// Intercept ActivityPub client requests
2import * as express from 'express' 2import * as express from 'express'
3import { pageToStartAndCount } from '../../helpers' 3import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers'
4import { activityPubCollectionPagination } from '../../helpers/activitypub' 4import { ACTIVITY_PUB, CONFIG } from '../../initializers'
5 5import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send'
6import { database as db } from '../../initializers'
7import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants'
8import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send/send-announce'
9import { buildVideoAnnounceToFollowers } from '../../lib/index' 6import { buildVideoAnnounceToFollowers } from '../../lib/index'
10import { executeIfActivityPub, localAccountValidator } from '../../middlewares' 7import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares'
11import { asyncMiddleware } from '../../middlewares/async' 8import {
12import { videoChannelsGetValidator, videoChannelsShareValidator } from '../../middlewares/validators/video-channels' 9 videoChannelsGetValidator,
13import { videosGetValidator, videosShareValidator } from '../../middlewares/validators/videos' 10 videoChannelsShareValidator,
14import { AccountInstance, VideoChannelInstance } from '../../models' 11 videosGetValidator,
15import { VideoChannelShareInstance } from '../../models/video/video-channel-share-interface' 12 videosShareValidator
16import { VideoInstance } from '../../models/video/video-interface' 13} from '../../middlewares/validators'
17import { VideoShareInstance } from '../../models/video/video-share-interface' 14import { AccountModel } from '../../models/account/account'
15import { AccountFollowModel } from '../../models/account/account-follow'
16import { VideoModel } from '../../models/video/video'
17import { VideoChannelModel } from '../../models/video/video-channel'
18import { VideoChannelShareModel } from '../../models/video/video-channel-share'
19import { VideoShareModel } from '../../models/video/video-share'
18 20
19const activityPubClientRouter = express.Router() 21const activityPubClientRouter = express.Router()
20 22
@@ -62,57 +64,57 @@ export {
62// --------------------------------------------------------------------------- 64// ---------------------------------------------------------------------------
63 65
64function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { 66function accountController (req: express.Request, res: express.Response, next: express.NextFunction) {
65 const account: AccountInstance = res.locals.account 67 const account: AccountModel = res.locals.account
66 68
67 return res.json(account.toActivityPubObject()).end() 69 return res.json(account.toActivityPubObject()).end()
68} 70}
69 71
70async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { 72async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
71 const account: AccountInstance = res.locals.account 73 const account: AccountModel = res.locals.account
72 74
73 const page = req.query.page || 1 75 const page = req.query.page || 1
74 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 76 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
75 77
76 const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) 78 const result = await AccountFollowModel.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count)
77 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) 79 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
78 80
79 return res.json(activityPubResult) 81 return res.json(activityPubResult)
80} 82}
81 83
82async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { 84async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
83 const account: AccountInstance = res.locals.account 85 const account: AccountModel = res.locals.account
84 86
85 const page = req.query.page || 1 87 const page = req.query.page || 1
86 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 88 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
87 89
88 const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) 90 const result = await AccountFollowModel.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count)
89 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) 91 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
90 92
91 return res.json(activityPubResult) 93 return res.json(activityPubResult)
92} 94}
93 95
94function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { 96function videoController (req: express.Request, res: express.Response, next: express.NextFunction) {
95 const video: VideoInstance = res.locals.video 97 const video: VideoModel = res.locals.video
96 98
97 return res.json(video.toActivityPubObject()) 99 return res.json(video.toActivityPubObject())
98} 100}
99 101
100async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 102async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
101 const share = res.locals.videoShare as VideoShareInstance 103 const share = res.locals.videoShare as VideoShareModel
102 const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) 104 const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined)
103 105
104 return res.json(object) 106 return res.json(object)
105} 107}
106 108
107async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { 109async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) {
108 const share = res.locals.videoChannelShare as VideoChannelShareInstance 110 const share = res.locals.videoChannelShare as VideoChannelShareModel
109 const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) 111 const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined)
110 112
111 return res.json(object) 113 return res.json(object)
112} 114}
113 115
114async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { 116async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) {
115 const videoChannel: VideoChannelInstance = res.locals.videoChannel 117 const videoChannel: VideoChannelModel = res.locals.videoChannel
116 118
117 return res.json(videoChannel.toActivityPubObject()) 119 return res.json(videoChannel.toActivityPubObject())
118} 120}
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts
index 5a2d43f3d..dc6b72a6e 100644
--- a/server/controllers/activitypub/outbox.ts
+++ b/server/controllers/activitypub/outbox.ts
@@ -2,13 +2,13 @@ import * as express from 'express'
2import { Activity } from '../../../shared/models/activitypub/activity' 2import { Activity } from '../../../shared/models/activitypub/activity'
3import { activityPubCollectionPagination } from '../../helpers/activitypub' 3import { activityPubCollectionPagination } from '../../helpers/activitypub'
4import { pageToStartAndCount } from '../../helpers/core-utils' 4import { pageToStartAndCount } from '../../helpers/core-utils'
5import { database as db } from '../../initializers'
6import { ACTIVITY_PUB } from '../../initializers/constants' 5import { ACTIVITY_PUB } from '../../initializers/constants'
7import { addActivityData } from '../../lib/activitypub/send/send-add' 6import { addActivityData } from '../../lib/activitypub/send/send-add'
8import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' 7import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
9import { announceActivityData } from '../../lib/index' 8import { announceActivityData } from '../../lib/index'
10import { asyncMiddleware, localAccountValidator } from '../../middlewares' 9import { asyncMiddleware, localAccountValidator } from '../../middlewares'
11import { AccountInstance } from '../../models/account/account-interface' 10import { AccountModel } from '../../models/account/account'
11import { VideoModel } from '../../models/video/video'
12 12
13const outboxRouter = express.Router() 13const outboxRouter = express.Router()
14 14
@@ -26,12 +26,12 @@ export {
26// --------------------------------------------------------------------------- 26// ---------------------------------------------------------------------------
27 27
28async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { 28async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) {
29 const account: AccountInstance = res.locals.account 29 const account: AccountModel = res.locals.account
30 30
31 const page = req.query.page || 1 31 const page = req.query.page || 1
32 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) 32 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
33 33
34 const data = await db.Video.listAllAndSharedByAccountForOutbox(account.id, start, count) 34 const data = await VideoModel.listAllAndSharedByAccountForOutbox(account.id, start, count)
35 const activities: Activity[] = [] 35 const activities: Activity[] = []
36 36
37 for (const video of data.data) { 37 for (const video of data.data) {