mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Add ability to view my followers
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ export {
|
||||
|
||||
async function listFollowing (req: express.Request, res: express.Response) {
|
||||
const serverActor = await getServerActor()
|
||||
const resultList = await ActorFollowModel.listFollowingForApi({
|
||||
const resultList = await ActorFollowModel.listInstanceFollowingForApi({
|
||||
id: serverActor.id,
|
||||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
@@ -114,7 +114,7 @@ async function listFollowing (req: express.Request, res: express.Response) {
|
||||
async function listFollowers (req: express.Request, res: express.Response) {
|
||||
const serverActor = await getServerActor()
|
||||
const resultList = await ActorFollowModel.listFollowersForApi({
|
||||
actorId: serverActor.id,
|
||||
actorIds: [ serverActor.id ],
|
||||
start: req.query.start,
|
||||
count: req.query.count,
|
||||
sort: req.query.sort,
|
||||
|
||||
@@ -95,7 +95,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons
|
||||
return { name, host, uri: u }
|
||||
})
|
||||
|
||||
const results = await ActorFollowModel.listSubscribedIn(user.Account.Actor.id, handles)
|
||||
const results = await ActorFollowModel.listSubscriptionsOf(user.Account.Actor.id, handles)
|
||||
|
||||
const existObject: { [id: string ]: boolean } = {}
|
||||
for (const handle of handles) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import express from 'express'
|
||||
import { pickCommonVideoQuery } from '@server/helpers/query'
|
||||
import { Hooks } from '@server/lib/plugins/hooks'
|
||||
import { ActorFollowModel } from '@server/models/actor/actor-follow'
|
||||
import { getServerActor } from '@server/models/application/application'
|
||||
import { MChannelBannerAccountDefault } from '@server/types/models'
|
||||
import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
|
||||
@@ -33,7 +34,13 @@ import {
|
||||
videoChannelsUpdateValidator,
|
||||
videoPlaylistsSortValidator
|
||||
} from '../../middlewares'
|
||||
import { videoChannelsListValidator, videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators'
|
||||
import {
|
||||
ensureAuthUserOwnsChannelValidator,
|
||||
videoChannelsFollowersSortValidator,
|
||||
videoChannelsListValidator,
|
||||
videoChannelsNameWithHostValidator,
|
||||
videosSortValidator
|
||||
} from '../../middlewares/validators'
|
||||
import { updateAvatarValidator, updateBannerValidator } from '../../middlewares/validators/actor-image'
|
||||
import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
|
||||
import { AccountModel } from '../../models/account/account'
|
||||
@@ -65,8 +72,8 @@ videoChannelRouter.post('/',
|
||||
videoChannelRouter.post('/:nameWithHost/avatar/pick',
|
||||
authenticate,
|
||||
reqAvatarFile,
|
||||
// Check the rights
|
||||
asyncMiddleware(videoChannelsUpdateValidator),
|
||||
asyncMiddleware(videoChannelsNameWithHostValidator),
|
||||
ensureAuthUserOwnsChannelValidator,
|
||||
updateAvatarValidator,
|
||||
asyncMiddleware(updateVideoChannelAvatar)
|
||||
)
|
||||
@@ -74,29 +81,31 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick',
|
||||
videoChannelRouter.post('/:nameWithHost/banner/pick',
|
||||
authenticate,
|
||||
reqBannerFile,
|
||||
// Check the rights
|
||||
asyncMiddleware(videoChannelsUpdateValidator),
|
||||
asyncMiddleware(videoChannelsNameWithHostValidator),
|
||||
ensureAuthUserOwnsChannelValidator,
|
||||
updateBannerValidator,
|
||||
asyncMiddleware(updateVideoChannelBanner)
|
||||
)
|
||||
|
||||
videoChannelRouter.delete('/:nameWithHost/avatar',
|
||||
authenticate,
|
||||
// Check the rights
|
||||
asyncMiddleware(videoChannelsUpdateValidator),
|
||||
asyncMiddleware(videoChannelsNameWithHostValidator),
|
||||
ensureAuthUserOwnsChannelValidator,
|
||||
asyncMiddleware(deleteVideoChannelAvatar)
|
||||
)
|
||||
|
||||
videoChannelRouter.delete('/:nameWithHost/banner',
|
||||
authenticate,
|
||||
// Check the rights
|
||||
asyncMiddleware(videoChannelsUpdateValidator),
|
||||
asyncMiddleware(videoChannelsNameWithHostValidator),
|
||||
ensureAuthUserOwnsChannelValidator,
|
||||
asyncMiddleware(deleteVideoChannelBanner)
|
||||
)
|
||||
|
||||
videoChannelRouter.put('/:nameWithHost',
|
||||
authenticate,
|
||||
asyncMiddleware(videoChannelsUpdateValidator),
|
||||
asyncMiddleware(videoChannelsNameWithHostValidator),
|
||||
ensureAuthUserOwnsChannelValidator,
|
||||
videoChannelsUpdateValidator,
|
||||
asyncRetryTransactionMiddleware(updateVideoChannel)
|
||||
)
|
||||
|
||||
@@ -132,6 +141,17 @@ videoChannelRouter.get('/:nameWithHost/videos',
|
||||
asyncMiddleware(listVideoChannelVideos)
|
||||
)
|
||||
|
||||
videoChannelRouter.get('/:nameWithHost/followers',
|
||||
authenticate,
|
||||
asyncMiddleware(videoChannelsNameWithHostValidator),
|
||||
ensureAuthUserOwnsChannelValidator,
|
||||
paginationValidator,
|
||||
videoChannelsFollowersSortValidator,
|
||||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
asyncMiddleware(listVideoChannelFollowers)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
@@ -332,3 +352,18 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon
|
||||
|
||||
return res.json(getFormattedObjects(resultList.data, resultList.total))
|
||||
}
|
||||
|
||||
async function listVideoChannelFollowers (req: express.Request, res: express.Response) {
|
||||
const channel = res.locals.videoChannel
|
||||
|
||||
const resultList = await ActorFollowModel.listFollowersForApi({
|
||||
actorIds: [ channel.actorId ],
|
||||
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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user