-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.js
92 lines (89 loc) · 2.37 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var Handle = require("./Handle.js");
var $$Object = require("./Object.js");
var Security = require("./Security.js");
var Belt_Option = require("rescript/lib/js/belt_Option.js");
async function handler($$event, param) {
var httpMethod = $$event.httpMethod;
var path = $$event.path;
console.log({
httpMethod: httpMethod,
path: path,
headers: $$event.headers
});
var post_verified = httpMethod === "POST" && await Security.Signature.verify($$event);
console.log("post_verified:", post_verified);
var activity = Belt_Option.map($$event.body, $$Object.fromString);
Belt_Option.forEach(activity, (function (x) {
if (x.TAG === /* Ok */0) {
console.log("body:", x._0);
return ;
}
console.log("Can't parse body as an ActivityStream Object:", x._0);
}));
var handlers = function (t) {
if (t === "Accept" || t === "Note" || t === "OrderedCollection") {
return function (param) {
return Promise.resolve({
statusCode: 400,
body: "Why are you sending this to me?"
});
};
} else if (t === "Delete") {
return Handle.$$delete;
} else if (t === "Follow") {
return Handle.follow;
} else if (t === "Create") {
return Handle.create;
} else if (t === "Like") {
return function (param) {
return Handle.like(false, param);
};
} else if (t === "Undo") {
return Handle.undo;
} else {
return function (param) {
return Handle.announce(false, param);
};
}
};
if (httpMethod === "GET") {
if (path === "/actor") {
return Handle.actor($$event);
} else {
return {
statusCode: 501
};
}
}
if (httpMethod !== "POST") {
return {
statusCode: 501
};
}
if (!post_verified) {
return {
statusCode: 401
};
}
if (path !== "/inbox") {
return {
statusCode: 501
};
}
if (activity === undefined) {
return {
statusCode: 501
};
}
if (activity.TAG !== /* Ok */0) {
return {
statusCode: 501
};
}
var act = activity._0;
return await handlers(act.type)(act);
}
exports.handler = handler;
/* Handle Not a pure module */