-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.js
38 lines (36 loc) · 1002 Bytes
/
list.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
/* eslint-disable no-console */
const ListService = require('./lib/list-service.js');
module.exports.list = (e, ctx, cb) => {
if (!e.requestContext.identity.cognitoIdentityId) {
cb(null, {
statusCode: 403,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: 'Missing authentication',
});
return;
}
const ls = new ListService();
ls.listFiles(`private/${e.requestContext.identity.cognitoIdentityId}/`)
.then(files => cb(null, {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify(files),
}))
.catch((err) => {
console.log(err);
cb(null, {
statusCode: err.code || 500,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: err.message,
});
});
};