-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (44 loc) · 1.34 KB
/
index.js
File metadata and controls
52 lines (44 loc) · 1.34 KB
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
const AWS = require("aws-sdk");
const documentClient = new AWS.DynamoDB.DocumentClient();
const tableName = "content";
exports.handler = async(event) => {
const params = {
TableName: tableName,
KeyConditionExpression: 'id = :hashKey',
//ProjectionExpression: "#id, #data, #url",
ExpressionAttributeValues: {
':hashKey': event.pathParameters.id,
},
// ExpressionAttributeNames: {
// "#data": "data",
// "#id": "id",
// "#url": "url"
// },
};
var data = await documentClient.query(params).promise();
if (!data.Items.length) {
return {
statusCode: 404,
headers: {
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify({ error: "Not found" })
};
}
if (event.headers.buid == data.Items[0].buid) {
data.Items[0].edit = true;
} else {
data.Items[0].edit = false;
}
delete data.Items[0].buid;
const response = {
statusCode: 200,
headers: {
'content-type': 'text/plain',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, buid'
},
body: data.Items[0].data
};
return response;
};