diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 4 | ||||
-rw-r--r-- | server/controllers/activitypub/index.ts | 5 | ||||
-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 | ||||
-rw-r--r-- | server/controllers/webfinger.ts | 2 |
6 files changed, 43 insertions, 34 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 56a4054fa..49dd24e79 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -46,7 +46,7 @@ async function accountFollowersController (req: express.Request, res: express.Re | |||
46 | const page = req.params.page || 1 | 46 | const page = req.params.page || 1 |
47 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 47 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
48 | 48 | ||
49 | const result = await db.Account.listAcceptedFollowerUrlsForApi(account.id, start, count) | 49 | const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi(account.id, start, count) |
50 | const activityPubResult = activityPubCollectionPagination(req.url, page, result) | 50 | const activityPubResult = activityPubCollectionPagination(req.url, page, result) |
51 | 51 | ||
52 | return res.json(activityPubResult) | 52 | return res.json(activityPubResult) |
@@ -58,7 +58,7 @@ async function accountFollowingController (req: express.Request, res: express.Re | |||
58 | const page = req.params.page || 1 | 58 | const page = req.params.page || 1 |
59 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 59 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
60 | 60 | ||
61 | const result = await db.Account.listAcceptedFollowingUrlsForApi(account.id, start, count) | 61 | const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi(account.id, start, count) |
62 | const activityPubResult = activityPubCollectionPagination(req.url, page, result) | 62 | const activityPubResult = activityPubCollectionPagination(req.url, page, result) |
63 | 63 | ||
64 | return res.json(activityPubResult) | 64 | return res.json(activityPubResult) |
diff --git a/server/controllers/activitypub/index.ts b/server/controllers/activitypub/index.ts index 0c8574ef7..c5bec6448 100644 --- a/server/controllers/activitypub/index.ts +++ b/server/controllers/activitypub/index.ts | |||
@@ -1,14 +1,11 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | |||
3 | import { badRequest } from '../../helpers' | ||
4 | import { inboxRouter } from './inbox' | ||
5 | import { activityPubClientRouter } from './client' | 2 | import { activityPubClientRouter } from './client' |
3 | import { inboxRouter } from './inbox' | ||
6 | 4 | ||
7 | const activityPubRouter = express.Router() | 5 | const activityPubRouter = express.Router() |
8 | 6 | ||
9 | activityPubRouter.use('/', inboxRouter) | 7 | activityPubRouter.use('/', inboxRouter) |
10 | activityPubRouter.use('/', activityPubClientRouter) | 8 | activityPubRouter.use('/', activityPubClientRouter) |
11 | activityPubRouter.use('/*', badRequest) | ||
12 | 9 | ||
13 | // --------------------------------------------------------------------------- | 10 | // --------------------------------------------------------------------------- |
14 | 11 | ||
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) |
diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts index 1c726f0cb..102ac0937 100644 --- a/server/controllers/webfinger.ts +++ b/server/controllers/webfinger.ts | |||
@@ -8,7 +8,7 @@ import { AccountInstance } from '../models/account/account-interface' | |||
8 | 8 | ||
9 | const webfingerRouter = express.Router() | 9 | const webfingerRouter = express.Router() |
10 | 10 | ||
11 | webfingerRouter.use('/.well-known/webfinger', | 11 | webfingerRouter.get('/.well-known/webfinger', |
12 | webfingerValidator, | 12 | webfingerValidator, |
13 | webfingerController | 13 | webfingerController |
14 | ) | 14 | ) |