-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (27 loc) · 815 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require('dotenv').config();
const flow = require('promise-control-flow');
const { getAddedContent } = require('./src/gitHubWebhook');
const MediumPublisher = require('./src/MediumPublisher');
exports.postMedium = (req, res) => {
getAddedContent(req.body)
.then((contentList) => {
if (!contentList) {
res.send(200);
return;
}
const postTaskList = contentList.map((content) => {
const client = new MediumPublisher();
return () => client.publish(content.title, content.content, content.tags, true);
});
flow.parallel(postTaskList)
.then(() => {
res.send(200);
}).catch((e) => {
console.error(e);
res.send(500);
});
}).catch((e) => {
console.error(e);
res.send(500);
});
};