This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
handler.js
83 lines (69 loc) · 2.23 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
const logger = require('fastlog')('sat-api');
const utils = require('./utils.js');
/**
* landsat handler function.
*
* @param {object} event - input
* @param {object} context -
* @param {function} callback -
*/
module.exports.landsat = (event, context, callback) => {
logger.info('Received event: ' + JSON.stringify(event));
if (event.row === '') return callback(new Error('ROW param missing!'));
if (event.path === '') return callback(new Error('PATH param missing!'));
utils.get_landsat(event.path, event.row, event.full)
.then(data => {
return callback(null, {
request: { path: event.path, row: event.row },
meta: { found: data.length },
results: data
});
})
.catch(err => {
logger.error(err);
return callback(new Error('API Error'));
});
};
module.exports.cbers = (event, context, callback) => {
logger.info('Received event: ' + JSON.stringify(event));
if (event.row === '') return callback(new Error('ROW param missing!'));
if (event.path === '') return callback(new Error('PATH param missing!'));
utils.get_cbers(event.path, event.row)
.then(data => {
return callback(null, {
request: { path: event.path, row: event.row },
meta: { found: data.length },
results: data
});
})
.catch(err => {
logger.error(err);
return callback(new Error('API Error'));
});
};
/**
* sentinel handler function.
*
* @param {object} event - input
* @param {object} context -
* @param {function} callback -
*/
module.exports.sentinel = (event, context, callback) => {
logger.info('Received event: ' + JSON.stringify(event));
if (event.utm === '') return callback(new Error('UTM param missing!'));
if (event.lat === '') return callback(new Error('LAT param missing!'));
if (event.grid === '') return callback(new Error('GRID param missing!'));
utils.get_sentinel(event.utm, event.lat, event.grid, event.full)
.then(data => {
return callback(null, {
request: { utm: event.utm, lat: event.lat, grid: event.grid},
meta: { found: data.length },
results: data
});
})
.catch(err => {
logger.error(err);
return callback(new Error('API Error'));
});
};