aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/client.ts63
1 files changed, 45 insertions, 18 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index ec3f72b64..ba659984f 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -10,6 +10,7 @@ import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '..
10import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' 10import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators'
11import { videoCommentGetValidator } from '../../middlewares/validators/video-comments' 11import { videoCommentGetValidator } from '../../middlewares/validators/video-comments'
12import { AccountModel } from '../../models/account/account' 12import { AccountModel } from '../../models/account/account'
13import { ActorModel } from '../../models/activitypub/actor'
13import { ActorFollowModel } from '../../models/activitypub/actor-follow' 14import { ActorFollowModel } from '../../models/activitypub/actor-follow'
14import { VideoModel } from '../../models/video/video' 15import { VideoModel } from '../../models/video/video'
15import { VideoChannelModel } from '../../models/video/video-channel' 16import { VideoChannelModel } from '../../models/video/video-channel'
@@ -22,13 +23,11 @@ activityPubClientRouter.get('/accounts?/:name',
22 executeIfActivityPub(asyncMiddleware(localAccountValidator)), 23 executeIfActivityPub(asyncMiddleware(localAccountValidator)),
23 executeIfActivityPub(accountController) 24 executeIfActivityPub(accountController)
24) 25)
25 26activityPubClientRouter.get('/accounts?/:name/followers',
26activityPubClientRouter.get('/accounts/:name/followers',
27 executeIfActivityPub(asyncMiddleware(localAccountValidator)), 27 executeIfActivityPub(asyncMiddleware(localAccountValidator)),
28 executeIfActivityPub(asyncMiddleware(accountFollowersController)) 28 executeIfActivityPub(asyncMiddleware(accountFollowersController))
29) 29)
30 30activityPubClientRouter.get('/accounts?/:name/following',
31activityPubClientRouter.get('/accounts/:name/following',
32 executeIfActivityPub(asyncMiddleware(localAccountValidator)), 31 executeIfActivityPub(asyncMiddleware(localAccountValidator)),
33 executeIfActivityPub(asyncMiddleware(accountFollowingController)) 32 executeIfActivityPub(asyncMiddleware(accountFollowingController))
34) 33)
@@ -37,12 +36,10 @@ activityPubClientRouter.get('/videos/watch/:id',
37 executeIfActivityPub(asyncMiddleware(videosGetValidator)), 36 executeIfActivityPub(asyncMiddleware(videosGetValidator)),
38 executeIfActivityPub(asyncMiddleware(videoController)) 37 executeIfActivityPub(asyncMiddleware(videoController))
39) 38)
40
41activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', 39activityPubClientRouter.get('/videos/watch/:id/announces/:accountId',
42 executeIfActivityPub(asyncMiddleware(videosShareValidator)), 40 executeIfActivityPub(asyncMiddleware(videosShareValidator)),
43 executeIfActivityPub(asyncMiddleware(videoAnnounceController)) 41 executeIfActivityPub(asyncMiddleware(videoAnnounceController))
44) 42)
45
46activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', 43activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId',
47 executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)), 44 executeIfActivityPub(asyncMiddleware(videoCommentGetValidator)),
48 executeIfActivityPub(asyncMiddleware(videoCommentController)) 45 executeIfActivityPub(asyncMiddleware(videoCommentController))
@@ -52,6 +49,14 @@ activityPubClientRouter.get('/video-channels/:id',
52 executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)), 49 executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)),
53 executeIfActivityPub(asyncMiddleware(videoChannelController)) 50 executeIfActivityPub(asyncMiddleware(videoChannelController))
54) 51)
52activityPubClientRouter.get('/video-channels/:id/followers',
53 executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)),
54 executeIfActivityPub(asyncMiddleware(videoChannelFollowersController))
55)
56activityPubClientRouter.get('/video-channels/:id/following',
57 executeIfActivityPub(asyncMiddleware(videoChannelsGetValidator)),
58 executeIfActivityPub(asyncMiddleware(videoChannelFollowingController))
59)
55 60
56// --------------------------------------------------------------------------- 61// ---------------------------------------------------------------------------
57 62
@@ -70,24 +75,14 @@ function accountController (req: express.Request, res: express.Response, next: e
70 75
71async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { 76async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
72 const account: AccountModel = res.locals.account 77 const account: AccountModel = res.locals.account
73 78 const activityPubResult = await actorFollowers(req, account.Actor)
74 const page = req.query.page || 1
75 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
76
77 const result = await ActorFollowModel.listAcceptedFollowerUrlsForApi([ account.Actor.id ], undefined, start, count)
78 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
79 79
80 return res.json(activityPubResult) 80 return res.json(activityPubResult)
81} 81}
82 82
83async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { 83async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
84 const account: AccountModel = res.locals.account 84 const account: AccountModel = res.locals.account
85 85 const activityPubResult = await actorFollowing(req, account.Actor)
86 const page = req.query.page || 1
87 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
88
89 const result = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ account.Actor.id ], undefined, start, count)
90 const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
91 86
92 return res.json(activityPubResult) 87 return res.json(activityPubResult)
93} 88}
@@ -115,9 +110,41 @@ async function videoChannelController (req: express.Request, res: express.Respon
115 return res.json(videoChannel.toActivityPubObject()) 110 return res.json(videoChannel.toActivityPubObject())
116} 111}
117 112
113async function videoChannelFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) {
114 const videoChannel: VideoChannelModel = res.locals.videoChannel
115 const activityPubResult = await actorFollowers(req, videoChannel.Actor)
116
117 return res.json(activityPubResult)
118}
119
120async function videoChannelFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) {
121 const videoChannel: VideoChannelModel = res.locals.videoChannel
122 const activityPubResult = await actorFollowing(req, videoChannel.Actor)
123
124 return res.json(activityPubResult)
125}
126
118async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { 127async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) {
119 const videoComment: VideoCommentModel = res.locals.videoComment 128 const videoComment: VideoCommentModel = res.locals.videoComment
120 129
121 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) 130 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined)
122 return res.json(videoComment.toActivityPubObject(threadParentComments)) 131 return res.json(videoComment.toActivityPubObject(threadParentComments))
123} 132}
133
134// ---------------------------------------------------------------------------
135
136async function actorFollowing (req: express.Request, actor: ActorModel) {
137 const page = req.query.page || 1
138 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
139
140 const result = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count)
141 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
142}
143
144async function actorFollowers (req: express.Request, actor: ActorModel) {
145 const page = req.query.page || 1
146 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
147
148 const result = await ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count)
149 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result)
150}