aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users/me.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-23 17:58:39 +0200
committerChocobozzz <me@florianbigard.com>2018-08-27 09:41:54 +0200
commitf37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9 (patch)
tree2050443febcdb2a3eec68b7bbf9687e26dcb24dc /server/controllers/api/users/me.ts
parent240085d0056fd97ac3c7fa8fa4ce9bc32afc4d6e (diff)
downloadPeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.gz
PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.tar.zst
PeerTube-f37dc0dd14d9ce0b59c454c2c1b935fcbe9727e9.zip
Add ability to search video channels
Diffstat (limited to 'server/controllers/api/users/me.ts')
-rw-r--r--server/controllers/api/users/me.ts41
1 files changed, 39 insertions, 2 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index 2300f5dbe..000c706b5 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -20,7 +20,8 @@ import {
20 deleteMeValidator, 20 deleteMeValidator,
21 userSubscriptionsSortValidator, 21 userSubscriptionsSortValidator,
22 videoImportsSortValidator, 22 videoImportsSortValidator,
23 videosSortValidator 23 videosSortValidator,
24 areSubscriptionsExistValidator
24} from '../../../middlewares/validators' 25} from '../../../middlewares/validators'
25import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 26import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
26import { UserModel } from '../../../models/account/user' 27import { UserModel } from '../../../models/account/user'
@@ -99,7 +100,6 @@ meRouter.post('/me/avatar/pick',
99 100
100meRouter.get('/me/subscriptions/videos', 101meRouter.get('/me/subscriptions/videos',
101 authenticate, 102 authenticate,
102 authenticate,
103 paginationValidator, 103 paginationValidator,
104 videosSortValidator, 104 videosSortValidator,
105 setDefaultSort, 105 setDefaultSort,
@@ -108,6 +108,12 @@ meRouter.get('/me/subscriptions/videos',
108 asyncMiddleware(getUserSubscriptionVideos) 108 asyncMiddleware(getUserSubscriptionVideos)
109) 109)
110 110
111meRouter.get('/me/subscriptions/exist',
112 authenticate,
113 areSubscriptionsExistValidator,
114 asyncMiddleware(areSubscriptionsExist)
115)
116
111meRouter.get('/me/subscriptions', 117meRouter.get('/me/subscriptions',
112 authenticate, 118 authenticate,
113 paginationValidator, 119 paginationValidator,
@@ -143,6 +149,37 @@ export {
143 149
144// --------------------------------------------------------------------------- 150// ---------------------------------------------------------------------------
145 151
152async function areSubscriptionsExist (req: express.Request, res: express.Response) {
153 const uris = req.query.uris as string[]
154 const user = res.locals.oauth.token.User as UserModel
155
156 const handles = uris.map(u => {
157 let [ name, host ] = u.split('@')
158 if (host === CONFIG.WEBSERVER.HOST) host = null
159
160 return { name, host, uri: u }
161 })
162
163 const results = await ActorFollowModel.listSubscribedIn(user.Account.Actor.id, handles)
164
165 const existObject: { [id: string ]: boolean } = {}
166 for (const handle of handles) {
167 const obj = results.find(r => {
168 const server = r.ActorFollowing.Server
169
170 return r.ActorFollowing.preferredUsername === handle.name &&
171 (
172 (!server && !handle.host) ||
173 (server.host === handle.host)
174 )
175 })
176
177 existObject[handle.uri] = obj !== undefined
178 }
179
180 return res.json(existObject)
181}
182
146async function addUserSubscription (req: express.Request, res: express.Response) { 183async function addUserSubscription (req: express.Request, res: express.Response) {
147 const user = res.locals.oauth.token.User as UserModel 184 const user = res.locals.oauth.token.User as UserModel
148 const [ name, host ] = req.body.uri.split('@') 185 const [ name, host ] = req.body.uri.split('@')