diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/application/follows.ts (renamed from server/controllers/api/pods.ts) | 50 | ||||
-rw-r--r-- | server/controllers/api/application/index.ts | 12 | ||||
-rw-r--r-- | server/controllers/api/index.ts | 4 |
3 files changed, 39 insertions, 27 deletions
diff --git a/server/controllers/api/pods.ts b/server/controllers/api/application/follows.ts index 0bd6971bb..000bbd23e 100644 --- a/server/controllers/api/pods.ts +++ b/server/controllers/api/application/follows.ts | |||
@@ -1,23 +1,23 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { UserRight } from '../../../shared/models/users/user-right.enum' | 2 | import { UserRight } from '../../../../shared/models/users/user-right.enum' |
3 | import { getFormattedObjects } from '../../helpers' | 3 | import { getFormattedObjects } from '../../../helpers' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../../helpers/logger' |
5 | import { getApplicationAccount } from '../../helpers/utils' | 5 | import { getApplicationAccount } from '../../../helpers/utils' |
6 | import { getAccountFromWebfinger } from '../../helpers/webfinger' | 6 | import { getAccountFromWebfinger } from '../../../helpers/webfinger' |
7 | import { SERVER_ACCOUNT_NAME } from '../../initializers/constants' | 7 | import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants' |
8 | import { database as db } from '../../initializers/database' | 8 | import { database as db } from '../../../initializers/database' |
9 | import { sendFollow } from '../../lib/activitypub/send-request' | 9 | import { sendFollow } from '../../../lib/activitypub/send-request' |
10 | import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares' | 10 | import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../../middlewares' |
11 | import { authenticate } from '../../middlewares/oauth' | 11 | import { authenticate } from '../../../middlewares/oauth' |
12 | import { setBodyHostsPort } from '../../middlewares/pods' | 12 | import { setBodyHostsPort } from '../../../middlewares/pods' |
13 | import { setFollowingSort } from '../../middlewares/sort' | 13 | import { setFollowingSort } from '../../../middlewares/sort' |
14 | import { ensureUserHasRight } from '../../middlewares/user-right' | 14 | import { ensureUserHasRight } from '../../../middlewares/user-right' |
15 | import { followValidator } from '../../middlewares/validators/pods' | 15 | import { followValidator } from '../../../middlewares/validators/pods' |
16 | import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort' | 16 | import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort' |
17 | 17 | ||
18 | const podsRouter = express.Router() | 18 | const applicationFollowsRouter = express.Router() |
19 | 19 | ||
20 | podsRouter.get('/following', | 20 | applicationFollowsRouter.get('/following', |
21 | paginationValidator, | 21 | paginationValidator, |
22 | followingSortValidator, | 22 | followingSortValidator, |
23 | setFollowingSort, | 23 | setFollowingSort, |
@@ -25,15 +25,15 @@ podsRouter.get('/following', | |||
25 | asyncMiddleware(listFollowing) | 25 | asyncMiddleware(listFollowing) |
26 | ) | 26 | ) |
27 | 27 | ||
28 | podsRouter.post('/follow', | 28 | applicationFollowsRouter.post('/follow', |
29 | authenticate, | 29 | authenticate, |
30 | ensureUserHasRight(UserRight.MANAGE_PEERTUBE_FOLLOW), | 30 | ensureUserHasRight(UserRight.MANAGE_APPLICATION_FOLLOW), |
31 | followValidator, | 31 | followValidator, |
32 | setBodyHostsPort, | 32 | setBodyHostsPort, |
33 | asyncMiddleware(follow) | 33 | asyncMiddleware(follow) |
34 | ) | 34 | ) |
35 | 35 | ||
36 | podsRouter.get('/followers', | 36 | applicationFollowsRouter.get('/followers', |
37 | paginationValidator, | 37 | paginationValidator, |
38 | followersSortValidator, | 38 | followersSortValidator, |
39 | setFollowersSort, | 39 | setFollowersSort, |
@@ -44,21 +44,21 @@ podsRouter.get('/followers', | |||
44 | // --------------------------------------------------------------------------- | 44 | // --------------------------------------------------------------------------- |
45 | 45 | ||
46 | export { | 46 | export { |
47 | podsRouter | 47 | applicationFollowsRouter |
48 | } | 48 | } |
49 | 49 | ||
50 | // --------------------------------------------------------------------------- | 50 | // --------------------------------------------------------------------------- |
51 | 51 | ||
52 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { | 52 | async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) { |
53 | const applicationAccount = await getApplicationAccount() | 53 | const applicationAccount = await getApplicationAccount() |
54 | const resultList = await db.Account.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort) | 54 | const resultList = await db.AccountFollow.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort) |
55 | 55 | ||
56 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 56 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
57 | } | 57 | } |
58 | 58 | ||
59 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { | 59 | async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) { |
60 | const applicationAccount = await getApplicationAccount() | 60 | const applicationAccount = await getApplicationAccount() |
61 | const resultList = await db.Account.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort) | 61 | const resultList = await db.AccountFollow.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort) |
62 | 62 | ||
63 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 63 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
64 | } | 64 | } |
diff --git a/server/controllers/api/application/index.ts b/server/controllers/api/application/index.ts new file mode 100644 index 000000000..011b971ed --- /dev/null +++ b/server/controllers/api/application/index.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | import * as express from 'express' | ||
2 | import { applicationFollowsRouter } from './follows' | ||
3 | |||
4 | const applicationRouter = express.Router() | ||
5 | |||
6 | applicationRouter.use('/', applicationFollowsRouter) | ||
7 | |||
8 | // --------------------------------------------------------------------------- | ||
9 | |||
10 | export { | ||
11 | applicationRouter | ||
12 | } | ||
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 2e949d531..a22c78cce 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -4,15 +4,15 @@ import { badRequest } from '../../helpers' | |||
4 | 4 | ||
5 | import { oauthClientsRouter } from './oauth-clients' | 5 | import { oauthClientsRouter } from './oauth-clients' |
6 | import { configRouter } from './config' | 6 | import { configRouter } from './config' |
7 | import { podsRouter } from './pods' | 7 | import { applicationRouter } from './application' |
8 | import { usersRouter } from './users' | 8 | import { usersRouter } from './users' |
9 | import { videosRouter } from './videos' | 9 | import { videosRouter } from './videos' |
10 | 10 | ||
11 | const apiRouter = express.Router() | 11 | const apiRouter = express.Router() |
12 | 12 | ||
13 | apiRouter.use('/application', applicationRouter) | ||
13 | apiRouter.use('/oauth-clients', oauthClientsRouter) | 14 | apiRouter.use('/oauth-clients', oauthClientsRouter) |
14 | apiRouter.use('/config', configRouter) | 15 | apiRouter.use('/config', configRouter) |
15 | apiRouter.use('/pods', podsRouter) | ||
16 | apiRouter.use('/users', usersRouter) | 16 | apiRouter.use('/users', usersRouter) |
17 | apiRouter.use('/videos', videosRouter) | 17 | apiRouter.use('/videos', videosRouter) |
18 | apiRouter.use('/ping', pong) | 18 | apiRouter.use('/ping', pong) |