diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-20 14:15:15 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 13:35:31 +0200 |
commit | 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef (patch) | |
tree | 20bcdd660ab4eb731814db3a4a40fffb48ce7482 /server/controllers | |
parent | 7f28f2ddbaeecf451d501e99ded0408c14a33600 (diff) | |
download | PeerTube-4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef.tar.gz PeerTube-4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef.tar.zst PeerTube-4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef.zip |
Add ability for instances to follow any actor
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/server/follows.ts | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index e6f4f6b92..cbe6b7e4f 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts | |||
@@ -29,6 +29,7 @@ import { | |||
29 | removeFollowingValidator | 29 | removeFollowingValidator |
30 | } from '../../../middlewares/validators' | 30 | } from '../../../middlewares/validators' |
31 | import { ActorFollowModel } from '../../../models/actor/actor-follow' | 31 | import { ActorFollowModel } from '../../../models/actor/actor-follow' |
32 | import { ServerFollowCreate } from '@shared/models' | ||
32 | 33 | ||
33 | const serverFollowsRouter = express.Router() | 34 | const serverFollowsRouter = express.Router() |
34 | serverFollowsRouter.get('/following', | 35 | serverFollowsRouter.get('/following', |
@@ -45,10 +46,10 @@ serverFollowsRouter.post('/following', | |||
45 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 46 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
46 | followValidator, | 47 | followValidator, |
47 | setBodyHostsPort, | 48 | setBodyHostsPort, |
48 | asyncMiddleware(followInstance) | 49 | asyncMiddleware(addFollow) |
49 | ) | 50 | ) |
50 | 51 | ||
51 | serverFollowsRouter.delete('/following/:host', | 52 | serverFollowsRouter.delete('/following/:hostOrHandle', |
52 | authenticate, | 53 | authenticate, |
53 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), | 54 | ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), |
54 | asyncMiddleware(removeFollowingValidator), | 55 | asyncMiddleware(removeFollowingValidator), |
@@ -125,8 +126,8 @@ async function listFollowers (req: express.Request, res: express.Response) { | |||
125 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 126 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
126 | } | 127 | } |
127 | 128 | ||
128 | async function followInstance (req: express.Request, res: express.Response) { | 129 | async function addFollow (req: express.Request, res: express.Response) { |
129 | const hosts = req.body.hosts as string[] | 130 | const { hosts, handles } = req.body as ServerFollowCreate |
130 | const follower = await getServerActor() | 131 | const follower = await getServerActor() |
131 | 132 | ||
132 | for (const host of hosts) { | 133 | for (const host of hosts) { |
@@ -139,6 +140,18 @@ async function followInstance (req: express.Request, res: express.Response) { | |||
139 | JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) | 140 | JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) |
140 | } | 141 | } |
141 | 142 | ||
143 | for (const handle of handles) { | ||
144 | const [ name, host ] = handle.split('@') | ||
145 | |||
146 | const payload = { | ||
147 | host, | ||
148 | name, | ||
149 | followerActorId: follower.id | ||
150 | } | ||
151 | |||
152 | JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) | ||
153 | } | ||
154 | |||
142 | return res.status(HttpStatusCode.NO_CONTENT_204).end() | 155 | return res.status(HttpStatusCode.NO_CONTENT_204).end() |
143 | } | 156 | } |
144 | 157 | ||