diff options
Diffstat (limited to 'server/controllers/api/pods.ts')
-rw-r--r-- | server/controllers/api/pods.ts | 71 |
1 files changed, 22 insertions, 49 deletions
diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts index 283105f6c..0f85ab51d 100644 --- a/server/controllers/api/pods.ts +++ b/server/controllers/api/pods.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { waterfall } from 'async' | ||
3 | 2 | ||
4 | import { database as db } from '../../initializers/database' | 3 | import { database as db } from '../../initializers/database' |
5 | import { CONFIG } from '../../initializers' | 4 | import { CONFIG } from '../../initializers' |
@@ -57,65 +56,39 @@ export { | |||
57 | function addPods (req: express.Request, res: express.Response, next: express.NextFunction) { | 56 | function addPods (req: express.Request, res: express.Response, next: express.NextFunction) { |
58 | const informations = req.body | 57 | const informations = req.body |
59 | 58 | ||
60 | waterfall<string, Error>([ | 59 | const pod = db.Pod.build(informations) |
61 | function addPod (callback) { | 60 | pod.save() |
62 | const pod = db.Pod.build(informations) | 61 | .then(podCreated => { |
63 | pod.save().asCallback(function (err, podCreated) { | 62 | return sendOwnedVideosToPod(podCreated.id) |
64 | // Be sure about the number of parameters for the callback | 63 | }) |
65 | return callback(err, podCreated) | 64 | .then(() => { |
66 | }) | 65 | return getMyPublicCert() |
67 | }, | 66 | }) |
68 | 67 | .then(cert => { | |
69 | function sendMyVideos (podCreated: PodInstance, callback) { | 68 | return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL }) |
70 | sendOwnedVideosToPod(podCreated.id) | 69 | }) |
71 | 70 | .catch(err => next(err)) | |
72 | callback(null) | ||
73 | }, | ||
74 | |||
75 | function fetchMyCertificate (callback) { | ||
76 | getMyPublicCert(function (err, cert) { | ||
77 | if (err) { | ||
78 | logger.error('Cannot read cert file.') | ||
79 | return callback(err) | ||
80 | } | ||
81 | |||
82 | return callback(null, cert) | ||
83 | }) | ||
84 | } | ||
85 | ], function (err, cert) { | ||
86 | if (err) return next(err) | ||
87 | |||
88 | return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL }) | ||
89 | }) | ||
90 | } | 71 | } |
91 | 72 | ||
92 | function listPods (req: express.Request, res: express.Response, next: express.NextFunction) { | 73 | function listPods (req: express.Request, res: express.Response, next: express.NextFunction) { |
93 | db.Pod.list(function (err, podsList) { | 74 | db.Pod.list() |
94 | if (err) return next(err) | 75 | .then(podsList => res.json(getFormatedObjects(podsList, podsList.length))) |
95 | 76 | .catch(err => next(err)) | |
96 | res.json(getFormatedObjects(podsList, podsList.length)) | ||
97 | }) | ||
98 | } | 77 | } |
99 | 78 | ||
100 | function makeFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) { | 79 | function makeFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) { |
101 | const hosts = req.body.hosts as string[] | 80 | const hosts = req.body.hosts as string[] |
102 | 81 | ||
103 | makeFriends(hosts, function (err) { | 82 | makeFriends(hosts) |
104 | if (err) { | 83 | .then(() => logger.info('Made friends!')) |
105 | logger.error('Could not make friends.', { error: err }) | 84 | .catch(err => logger.error('Could not make friends.', { error: err })) |
106 | return | ||
107 | } | ||
108 | |||
109 | logger.info('Made friends!') | ||
110 | }) | ||
111 | 85 | ||
86 | // Don't wait the process that could be long | ||
112 | res.type('json').status(204).end() | 87 | res.type('json').status(204).end() |
113 | } | 88 | } |
114 | 89 | ||
115 | function quitFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) { | 90 | function quitFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) { |
116 | quitFriends(function (err) { | 91 | quitFriends() |
117 | if (err) return next(err) | 92 | .then(() => res.type('json').status(204).end()) |
118 | 93 | .catch(err => next(err)) | |
119 | res.type('json').status(204).end() | ||
120 | }) | ||
121 | } | 94 | } |