This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
67 lines (56 loc) · 1.45 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict';
const neoQrCodeNode = require('./lib/index.js');
module.exports.generateNEP9 = (event, context, callback) => {
const maxAge = 31557600;
const ratio = 3.5;
const qrCodeOptions = {
errorCorrectionLevel: 'H',
margin: 2,
width: 200,
};
const errorResponse = {
statusCode: 404,
headers: { 'Content-Type': 'text/plain' },
body: 'Invalid URI parameters'
};
const address = event.pathParameters.address;
const properties = event.queryStringParameters;
const asset = properties && properties.asset;
let uri = neoQrCodeNode.generateUri(address, properties);
if (!uri) {
callback(null, {
statusCode: 404,
headers: { 'Content-Type': 'text/plain' },
body: 'Invalid URI parameters'
});
} else {
console.log(uri)
const options = {
uri,
asset,
qrCodeOptions,
ratio,
};
neoQrCodeNode.generateQrCode(options)
.then(imgBuffer => {
const response = {
"isBase64Encoded": true,
"statusCode": 200,
"headers": {
'Content-Type': 'image/png',
'Cache-Control': 'public, max-age=31536000'
},
"body": imgBuffer.toString('base64')
}
callback(null, response);
})
.catch(err => {
console.log('QR Code create error', err)
callback(null, {
statusCode: 404,
headers: { 'Content-Type': 'text/plain' },
body: 'error creating QR code'
});
});
}
};