From 4beda9e12adc7b1f3b178cecd6863ebf3cf431f1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 19 Oct 2021 09:44:43 +0200 Subject: Add ability to view my followers --- server/controllers/api/accounts.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'server/controllers/api/accounts.ts') 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 @@ import express from 'express' import { pickCommonVideoQuery } from '@server/helpers/query' +import { ActorFollowModel } from '@server/models/actor/actor-follow' import { getServerActor } from '@server/models/application/application' import { buildNSFWFilter, getCountVideos, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' import { getFormattedObjects } from '../../helpers/utils' @@ -20,6 +21,7 @@ import { } from '../../middlewares' import { accountNameWithHostGetValidator, + accountsFollowersSortValidator, accountsSortValidator, ensureAuthUserOwnsAccountValidator, videoChannelsSortValidator, @@ -93,6 +95,17 @@ accountsRouter.get('/:accountName/ratings', asyncMiddleware(listAccountRatings) ) +accountsRouter.get('/:accountName/followers', + authenticate, + asyncMiddleware(accountNameWithHostGetValidator), + ensureAuthUserOwnsAccountValidator, + paginationValidator, + accountsFollowersSortValidator, + setDefaultSort, + setDefaultPagination, + asyncMiddleware(listAccountFollowers) +) + // --------------------------------------------------------------------------- export { @@ -127,7 +140,7 @@ async function listAccountChannels (req: express.Request, res: express.Response) search: req.query.search } - const resultList = await VideoChannelModel.listByAccount(options) + const resultList = await VideoChannelModel.listByAccountForAPI(options) return res.json(getFormattedObjects(resultList.data, resultList.total)) } @@ -195,3 +208,21 @@ async function listAccountRatings (req: express.Request, res: express.Response) }) return res.json(getFormattedObjects(resultList.rows, resultList.count)) } + +async function listAccountFollowers (req: express.Request, res: express.Response) { + const account = res.locals.account + + const channels = await VideoChannelModel.listAllByAccount(account.id) + const actorIds = [ account.actorId ].concat(channels.map(c => c.actorId)) + + const resultList = await ActorFollowModel.listFollowersForApi({ + actorIds, + start: req.query.start, + count: req.query.count, + sort: req.query.sort, + search: req.query.search, + state: 'accepted', + }) + + return res.json(getFormattedObjects(resultList.data, resultList.total)) +} -- cgit v1.2.3