aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-19 09:44:43 +0200
committerChocobozzz <me@florianbigard.com>2021-10-20 09:25:44 +0200
commit4beda9e12adc7b1f3b178cecd6863ebf3cf431f1 (patch)
tree6244a10b286d66c6dcd7799aee630670d0493781 /server/controllers/api
parent9593a78ae1368a9ad8bb11044fce6fde2892701a (diff)
downloadPeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.gz
PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.zst
PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.zip
Add ability to view my followers
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/accounts.ts33
-rw-r--r--server/controllers/api/server/follows.ts4
-rw-r--r--server/controllers/api/users/my-subscriptions.ts2
-rw-r--r--server/controllers/api/video-channel.ts55
4 files changed, 80 insertions, 14 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}
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
index 76ed75186..c613386b2 100644
--- a/server/controllers/api/server/follows.ts
+++ b/server/controllers/api/server/follows.ts
@@ -98,7 +98,7 @@ export {
98 98
99async function listFollowing (req: express.Request, res: express.Response) { 99async function listFollowing (req: express.Request, res: express.Response) {
100 const serverActor = await getServerActor() 100 const serverActor = await getServerActor()
101 const resultList = await ActorFollowModel.listFollowingForApi({ 101 const resultList = await ActorFollowModel.listInstanceFollowingForApi({
102 id: serverActor.id, 102 id: serverActor.id,
103 start: req.query.start, 103 start: req.query.start,
104 count: req.query.count, 104 count: req.query.count,
@@ -114,7 +114,7 @@ async function listFollowing (req: express.Request, res: express.Response) {
114async function listFollowers (req: express.Request, res: express.Response) { 114async function listFollowers (req: express.Request, res: express.Response) {
115 const serverActor = await getServerActor() 115 const serverActor = await getServerActor()
116 const resultList = await ActorFollowModel.listFollowersForApi({ 116 const resultList = await ActorFollowModel.listFollowersForApi({
117 actorId: serverActor.id, 117 actorIds: [ serverActor.id ],
118 start: req.query.start, 118 start: req.query.start,
119 count: req.query.count, 119 count: req.query.count,
120 sort: req.query.sort, 120 sort: req.query.sort,
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts
index e3c0cf089..b2b441673 100644
--- a/server/controllers/api/users/my-subscriptions.ts
+++ b/server/controllers/api/users/my-subscriptions.ts
@@ -95,7 +95,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons
95 return { name, host, uri: u } 95 return { name, host, uri: u }
96 }) 96 })
97 97
98 const results = await ActorFollowModel.listSubscribedIn(user.Account.Actor.id, handles) 98 const results = await ActorFollowModel.listSubscriptionsOf(user.Account.Actor.id, handles)
99 99
100 const existObject: { [id: string ]: boolean } = {} 100 const existObject: { [id: string ]: boolean } = {}
101 for (const handle of handles) { 101 for (const handle of handles) {
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index b79dc5933..f370c7004 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -1,6 +1,7 @@
1import express from 'express' 1import express from 'express'
2import { pickCommonVideoQuery } from '@server/helpers/query' 2import { pickCommonVideoQuery } from '@server/helpers/query'
3import { Hooks } from '@server/lib/plugins/hooks' 3import { Hooks } from '@server/lib/plugins/hooks'
4import { ActorFollowModel } from '@server/models/actor/actor-follow'
4import { getServerActor } from '@server/models/application/application' 5import { getServerActor } from '@server/models/application/application'
5import { MChannelBannerAccountDefault } from '@server/types/models' 6import { MChannelBannerAccountDefault } from '@server/types/models'
6import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' 7import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
@@ -33,7 +34,13 @@ import {
33 videoChannelsUpdateValidator, 34 videoChannelsUpdateValidator,
34 videoPlaylistsSortValidator 35 videoPlaylistsSortValidator
35} from '../../middlewares' 36} from '../../middlewares'
36import { videoChannelsListValidator, videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' 37import {
38 ensureAuthUserOwnsChannelValidator,
39 videoChannelsFollowersSortValidator,
40 videoChannelsListValidator,
41 videoChannelsNameWithHostValidator,
42 videosSortValidator
43} from '../../middlewares/validators'
37import { updateAvatarValidator, updateBannerValidator } from '../../middlewares/validators/actor-image' 44import { updateAvatarValidator, updateBannerValidator } from '../../middlewares/validators/actor-image'
38import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' 45import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
39import { AccountModel } from '../../models/account/account' 46import { AccountModel } from '../../models/account/account'
@@ -65,8 +72,8 @@ videoChannelRouter.post('/',
65videoChannelRouter.post('/:nameWithHost/avatar/pick', 72videoChannelRouter.post('/:nameWithHost/avatar/pick',
66 authenticate, 73 authenticate,
67 reqAvatarFile, 74 reqAvatarFile,
68 // Check the rights 75 asyncMiddleware(videoChannelsNameWithHostValidator),
69 asyncMiddleware(videoChannelsUpdateValidator), 76 ensureAuthUserOwnsChannelValidator,
70 updateAvatarValidator, 77 updateAvatarValidator,
71 asyncMiddleware(updateVideoChannelAvatar) 78 asyncMiddleware(updateVideoChannelAvatar)
72) 79)
@@ -74,29 +81,31 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick',
74videoChannelRouter.post('/:nameWithHost/banner/pick', 81videoChannelRouter.post('/:nameWithHost/banner/pick',
75 authenticate, 82 authenticate,
76 reqBannerFile, 83 reqBannerFile,
77 // Check the rights 84 asyncMiddleware(videoChannelsNameWithHostValidator),
78 asyncMiddleware(videoChannelsUpdateValidator), 85 ensureAuthUserOwnsChannelValidator,
79 updateBannerValidator, 86 updateBannerValidator,
80 asyncMiddleware(updateVideoChannelBanner) 87 asyncMiddleware(updateVideoChannelBanner)
81) 88)
82 89
83videoChannelRouter.delete('/:nameWithHost/avatar', 90videoChannelRouter.delete('/:nameWithHost/avatar',
84 authenticate, 91 authenticate,
85 // Check the rights 92 asyncMiddleware(videoChannelsNameWithHostValidator),
86 asyncMiddleware(videoChannelsUpdateValidator), 93 ensureAuthUserOwnsChannelValidator,
87 asyncMiddleware(deleteVideoChannelAvatar) 94 asyncMiddleware(deleteVideoChannelAvatar)
88) 95)
89 96
90videoChannelRouter.delete('/:nameWithHost/banner', 97videoChannelRouter.delete('/:nameWithHost/banner',
91 authenticate, 98 authenticate,
92 // Check the rights 99 asyncMiddleware(videoChannelsNameWithHostValidator),
93 asyncMiddleware(videoChannelsUpdateValidator), 100 ensureAuthUserOwnsChannelValidator,
94 asyncMiddleware(deleteVideoChannelBanner) 101 asyncMiddleware(deleteVideoChannelBanner)
95) 102)
96 103
97videoChannelRouter.put('/:nameWithHost', 104videoChannelRouter.put('/:nameWithHost',
98 authenticate, 105 authenticate,
99 asyncMiddleware(videoChannelsUpdateValidator), 106 asyncMiddleware(videoChannelsNameWithHostValidator),
107 ensureAuthUserOwnsChannelValidator,
108 videoChannelsUpdateValidator,
100 asyncRetryTransactionMiddleware(updateVideoChannel) 109 asyncRetryTransactionMiddleware(updateVideoChannel)
101) 110)
102 111
@@ -132,6 +141,17 @@ videoChannelRouter.get('/:nameWithHost/videos',
132 asyncMiddleware(listVideoChannelVideos) 141 asyncMiddleware(listVideoChannelVideos)
133) 142)
134 143
144videoChannelRouter.get('/:nameWithHost/followers',
145 authenticate,
146 asyncMiddleware(videoChannelsNameWithHostValidator),
147 ensureAuthUserOwnsChannelValidator,
148 paginationValidator,
149 videoChannelsFollowersSortValidator,
150 setDefaultSort,
151 setDefaultPagination,
152 asyncMiddleware(listVideoChannelFollowers)
153)
154
135// --------------------------------------------------------------------------- 155// ---------------------------------------------------------------------------
136 156
137export { 157export {
@@ -332,3 +352,18 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon
332 352
333 return res.json(getFormattedObjects(resultList.data, resultList.total)) 353 return res.json(getFormattedObjects(resultList.data, resultList.total))
334} 354}
355
356async function listVideoChannelFollowers (req: express.Request, res: express.Response) {
357 const channel = res.locals.videoChannel
358
359 const resultList = await ActorFollowModel.listFollowersForApi({
360 actorIds: [ channel.actorId ],
361 start: req.query.start,
362 count: req.query.count,
363 sort: req.query.sort,
364 search: req.query.search,
365 state: 'accepted',
366 })
367
368 return res.json(getFormattedObjects(resultList.data, resultList.total))
369}