-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions.js
35 lines (27 loc) · 772 Bytes
/
functions.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
'use strict';
require('dotenv').config();
const lib = require('./');
// Your first function handler
module.exports.thumbnail = (event, context, callback) => {
if (!event.url || typeof event.url !== 'string') {
callback(new Error('Please provide an image url'));
}
if (!process.env.THUMBNAILS_BUCKET) {
callback(new Error('Please provide a THUMBNAILS_BUCKET env var'));
}
return lib.generateThumbnail(event.url)
.then(thumbnailUrl => {
const body = {
message: 'Success! Here is your thumbnail image:',
thumbnailUrl: thumbnailUrl,
};
const response = {
statusCode: 200,
body: JSON.stringify(body),
};
callback(null, response);
})
.catch(e => {
callback(e);
});
};