aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/accounts.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/accounts.ts')
-rw-r--r--server/controllers/api/accounts.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index 75679b0f4..77edfa7c2 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -1,5 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { pickCommonVideoQuery } from '@server/helpers/query' 2import { pickCommonVideoQuery } from '@server/helpers/query'
3import { ActorFollowModel } from '@server/models/actor/actor-follow'
3import { getServerActor } from '@server/models/application/application' 4import { getServerActor } from '@server/models/application/application'
4import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 5import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
5import { getFormattedObjects } from '../../helpers/utils' 6import { getFormattedObjects } from '../../helpers/utils'
@@ -20,6 +21,7 @@ import {
20} from '../../middlewares' 21} from '../../middlewares'
21import { 22import {
22 accountNameWithHostGetValidator, 23 accountNameWithHostGetValidator,
24 accountsFollowersSortValidator,
23 accountsSortValidator, 25 accountsSortValidator,
24 ensureAuthUserOwnsAccountValidator, 26 ensureAuthUserOwnsAccountValidator,
25 videoChannelsSortValidator, 27 videoChannelsSortValidator,
@@ -93,6 +95,17 @@ accountsRouter.get('/:accountName/ratings',
93 asyncMiddleware(listAccountRatings) 95 asyncMiddleware(listAccountRatings)
94) 96)
95 97
98accountsRouter.get('/:accountName/followers',
99 authenticate,
100 asyncMiddleware(accountNameWithHostGetValidator),
101 ensureAuthUserOwnsAccountValidator,
102 paginationValidator,
103 accountsFollowersSortValidator,
104 setDefaultSort,
105 setDefaultPagination,
106 asyncMiddleware(listAccountFollowers)
107)
108
96// --------------------------------------------------------------------------- 109// ---------------------------------------------------------------------------
97 110
98export { 111export {
@@ -127,7 +140,7 @@ async function listAccountChannels (req: express.Request, res: express.Response)
127 search: req.query.search 140 search: req.query.search
128 } 141 }
129 142
130 const resultList = await VideoChannelModel.listByAccount(options) 143 const resultList = await VideoChannelModel.listByAccountForAPI(options)
131 144
132 return res.json(getFormattedObjects(resultList.data, resultList.total)) 145 return res.json(getFormattedObjects(resultList.data, resultList.total))
133} 146}
@@ -195,3 +208,21 @@ async function listAccountRatings (req: express.Request, res: express.Response)
195 }) 208 })
196 return res.json(getFormattedObjects(resultList.rows, resultList.count)) 209 return res.json(getFormattedObjects(resultList.rows, resultList.count))
197} 210}
211
212async function listAccountFollowers (req: express.Request, res: express.Response) {
213 const account = res.locals.account
214
215 const channels = await VideoChannelModel.listAllByAccount(account.id)
216 const actorIds = [ account.actorId ].concat(channels.map(c => c.actorId))
217
218 const resultList = await ActorFollowModel.listFollowersForApi({
219 actorIds,
220 start: req.query.start,
221 count: req.query.count,
222 sort: req.query.sort,
223 search: req.query.search,
224 state: 'accepted',
225 })
226
227 return res.json(getFormattedObjects(resultList.data, resultList.total))
228}