-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (35 loc) · 1.13 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
'use strict';
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const utils = require('../utils');
exports.handler = async (event, context) => {
const check = utils.checkAuth(event);
if(check.error){
return utils.getResponse(check.error, null, 403);
}
let keys = null;
if (event.body !== null && event.body !== undefined) {
let body = JSON.parse(event.body);
if (body.keys){
keys = body.keys;
}
}
if(!keys) {
return utils.getResponse("no keys", null, 400);
}
await utils.setCredentials(AWS, process.env.ROLE);
let urls = [];
const signedUrlExpireSeconds = 60 * 5;
for(let key of keys) {
//var val = user + '/' + key;
let val = utils.adaptKey(event, key, check.user);
const url = s3.getSignedUrl('getObject', {
Bucket: check.bucket,
Key: val,
Expires: signedUrlExpireSeconds
});
urls.push(url);
}
var bodyContent = "{\"urls\":" + JSON.stringify(urls) + "}";
return utils.getResponse(null, bodyContent);
};