diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-19 09:44:43 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-10-20 09:25:44 +0200 |
commit | 4beda9e12adc7b1f3b178cecd6863ebf3cf431f1 (patch) | |
tree | 6244a10b286d66c6dcd7799aee630670d0493781 /server/controllers/api/video-channel.ts | |
parent | 9593a78ae1368a9ad8bb11044fce6fde2892701a (diff) | |
download | PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.gz PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.tar.zst PeerTube-4beda9e12adc7b1f3b178cecd6863ebf3cf431f1.zip |
Add ability to view my followers
Diffstat (limited to 'server/controllers/api/video-channel.ts')
-rw-r--r-- | server/controllers/api/video-channel.ts | 55 |
1 files changed, 45 insertions, 10 deletions
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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { pickCommonVideoQuery } from '@server/helpers/query' | 2 | import { pickCommonVideoQuery } from '@server/helpers/query' |
3 | import { Hooks } from '@server/lib/plugins/hooks' | 3 | import { Hooks } from '@server/lib/plugins/hooks' |
4 | import { ActorFollowModel } from '@server/models/actor/actor-follow' | ||
4 | import { getServerActor } from '@server/models/application/application' | 5 | import { getServerActor } from '@server/models/application/application' |
5 | import { MChannelBannerAccountDefault } from '@server/types/models' | 6 | import { MChannelBannerAccountDefault } from '@server/types/models' |
6 | import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' | 7 | import { ActorImageType, VideoChannelCreate, VideoChannelUpdate } from '../../../shared' |
@@ -33,7 +34,13 @@ import { | |||
33 | videoChannelsUpdateValidator, | 34 | videoChannelsUpdateValidator, |
34 | videoPlaylistsSortValidator | 35 | videoPlaylistsSortValidator |
35 | } from '../../middlewares' | 36 | } from '../../middlewares' |
36 | import { videoChannelsListValidator, videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' | 37 | import { |
38 | ensureAuthUserOwnsChannelValidator, | ||
39 | videoChannelsFollowersSortValidator, | ||
40 | videoChannelsListValidator, | ||
41 | videoChannelsNameWithHostValidator, | ||
42 | videosSortValidator | ||
43 | } from '../../middlewares/validators' | ||
37 | import { updateAvatarValidator, updateBannerValidator } from '../../middlewares/validators/actor-image' | 44 | import { updateAvatarValidator, updateBannerValidator } from '../../middlewares/validators/actor-image' |
38 | import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' | 45 | import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' |
39 | import { AccountModel } from '../../models/account/account' | 46 | import { AccountModel } from '../../models/account/account' |
@@ -65,8 +72,8 @@ videoChannelRouter.post('/', | |||
65 | videoChannelRouter.post('/:nameWithHost/avatar/pick', | 72 | videoChannelRouter.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', | |||
74 | videoChannelRouter.post('/:nameWithHost/banner/pick', | 81 | videoChannelRouter.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 | ||
83 | videoChannelRouter.delete('/:nameWithHost/avatar', | 90 | videoChannelRouter.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 | ||
90 | videoChannelRouter.delete('/:nameWithHost/banner', | 97 | videoChannelRouter.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 | ||
97 | videoChannelRouter.put('/:nameWithHost', | 104 | videoChannelRouter.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 | ||
144 | videoChannelRouter.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 | ||
137 | export { | 157 | export { |
@@ -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 | |||
356 | async 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 | } | ||