diff options
Diffstat (limited to 'server/controllers/api/pods.ts')
-rw-r--r-- | server/controllers/api/pods.ts | 66 |
1 files changed, 2 insertions, 64 deletions
diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts index b44cd6b83..43df3f66f 100644 --- a/server/controllers/api/pods.ts +++ b/server/controllers/api/pods.ts | |||
@@ -1,26 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | import { getFormattedObjects } from '../../helpers' | |
3 | import { database as db } from '../../initializers/database' | 3 | import { database as db } from '../../initializers/database' |
4 | import { logger, getFormattedObjects } from '../../helpers' | 4 | import { asyncMiddleware, paginationValidator, podsSortValidator, setPagination, setPodsSort } from '../../middlewares' |
5 | import { | ||
6 | makeFriends, | ||
7 | quitFriends, | ||
8 | removeFriend | ||
9 | } from '../../lib' | ||
10 | import { | ||
11 | authenticate, | ||
12 | ensureUserHasRight, | ||
13 | makeFriendsValidator, | ||
14 | setBodyHostsPort, | ||
15 | podRemoveValidator, | ||
16 | paginationValidator, | ||
17 | setPagination, | ||
18 | setPodsSort, | ||
19 | podsSortValidator, | ||
20 | asyncMiddleware | ||
21 | } from '../../middlewares' | ||
22 | import { PodInstance } from '../../models' | ||
23 | import { UserRight } from '../../../shared' | ||
24 | 5 | ||
25 | const podsRouter = express.Router() | 6 | const podsRouter = express.Router() |
26 | 7 | ||
@@ -31,24 +12,6 @@ podsRouter.get('/', | |||
31 | setPagination, | 12 | setPagination, |
32 | asyncMiddleware(listPods) | 13 | asyncMiddleware(listPods) |
33 | ) | 14 | ) |
34 | podsRouter.post('/make-friends', | ||
35 | authenticate, | ||
36 | ensureUserHasRight(UserRight.MANAGE_PODS), | ||
37 | makeFriendsValidator, | ||
38 | setBodyHostsPort, | ||
39 | asyncMiddleware(makeFriendsController) | ||
40 | ) | ||
41 | podsRouter.get('/quit-friends', | ||
42 | authenticate, | ||
43 | ensureUserHasRight(UserRight.MANAGE_PODS), | ||
44 | asyncMiddleware(quitFriendsController) | ||
45 | ) | ||
46 | podsRouter.delete('/:id', | ||
47 | authenticate, | ||
48 | ensureUserHasRight(UserRight.MANAGE_PODS), | ||
49 | podRemoveValidator, | ||
50 | asyncMiddleware(removeFriendController) | ||
51 | ) | ||
52 | 15 | ||
53 | // --------------------------------------------------------------------------- | 16 | // --------------------------------------------------------------------------- |
54 | 17 | ||
@@ -63,28 +26,3 @@ async function listPods (req: express.Request, res: express.Response, next: expr | |||
63 | 26 | ||
64 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 27 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
65 | } | 28 | } |
66 | |||
67 | async function makeFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
68 | const hosts = req.body.hosts as string[] | ||
69 | |||
70 | // Don't wait the process that could be long | ||
71 | makeFriends(hosts) | ||
72 | .then(() => logger.info('Made friends!')) | ||
73 | .catch(err => logger.error('Could not make friends.', err)) | ||
74 | |||
75 | return res.type('json').status(204).end() | ||
76 | } | ||
77 | |||
78 | async function quitFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
79 | await quitFriends() | ||
80 | |||
81 | return res.type('json').status(204).end() | ||
82 | } | ||
83 | |||
84 | async function removeFriendController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
85 | const pod = res.locals.pod as PodInstance | ||
86 | |||
87 | await removeFriend(pod) | ||
88 | |||
89 | return res.type('json').status(204).end() | ||
90 | } | ||