-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
43 lines (38 loc) · 827 Bytes
/
handler.js
File metadata and controls
43 lines (38 loc) · 827 Bytes
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
31
32
33
34
35
36
37
38
39
40
41
42
43
const { createNewContent } = require('./utils/update-readme.js')
const { createFBContents } = require('./utils/create-fb-post.js')
module.exports.contents = async event => {
if (!event.body) {
return {
statusCode: 404,
body: JSON.stringify(
{
message: 'We dont have body',
},
null,
2
),
};
}
const bodyObj = event.body.split('&').reduce((acc, item) => {
const itemArr = item.split('=')
return {
...acc,
[itemArr[0]]: itemArr[1]
}
}, {})
await createNewContent(bodyObj)
if (bodyObj.text !== '') {
await createFBContents(bodyObj.text)
}
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'successfully!',
url: bodyObj.text || '',
},
null,
2
),
};
};