-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
executable file
·51 lines (37 loc) · 1.3 KB
/
handler.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
'use strict';
const {downloadFileS3, uploadFileS3} = require('helpers/s3.helper');
module.exports.upload = async (event, context, callback) => {
if (event.source === 'serverless-plugin-warmup') {
return callback(null, 'Lambda is warm!')
}
const app_token = event["queryStringParameters"]['app_token'];
const id = event["queryStringParameters"]['id'];
const name = event["queryStringParameters"]['name'];
const file_name = event["queryStringParameters"]['file_name'];
const res = await uploadFileS3(app_token, id, name, file_name);
let response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify( {data: res}),
isBase64Encoded: false
};
callback(null, response);
};
module.exports.download = async (event, context, callback) => {
const app_token = event["queryStringParameters"]['app_token'];
const path = event["queryStringParameters"]['path'];
const res = await downloadFileS3(app_token, path);
let response = {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify( {data: res}),
isBase64Encoded: false
};
callback(null, response);
};