-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertHighlight.js
47 lines (42 loc) · 1.27 KB
/
insertHighlight.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
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: "ap-southeast-2"});
exports.handler = (event, context, callback) => {
console.log("Processing...");
const params = {
Item: {
date: Date.now(),
webpageURL: event.url,
highlightID: context.awsRequestId,
highlightText: event.text,
webpageTitle: event.title,
webpageTopic: event.topic,
highlightColour: event.colour,
highlightNotes: event.notes
},
TableName: "highlights",
ReturnValues: 'NONE',
};
const response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify({
date: Date.now(),
webpageURL: event.url,
highlightID: context.awsRequestId,
highlightText: event.text,
webpageTitle: event.title,
webpageTopic: event.topic
}),
};
let self = this;
docClient.put(params, (err, data) => {
if(err){
callback(err, null);
} else {
callback(null, params.Item);
}
})
};