-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·102 lines (88 loc) · 2.62 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
/**
* Entry point for AWS Lambda Service
*
* @module index
*/
const rootPrefix = '.',
apiName = require(rootPrefix + '/lib/globalConstant/apiName'),
apiVersions = require(rootPrefix + '/lib/globalConstant/apiVersions'),
sanitizer = require(rootPrefix + '/helpers/sanitizer'),
routeHelper = require(rootPrefix + '/routes/helper');
class Executor {
/**
* @param {Object} event
*
* @constructor
**/
constructor(event) {
const oThis = this;
oThis.event = event;
}
/**
* Get Resource and Parameters for the resource
*
* @return Object
**/
getResourceAndParamsForAction() {
const oThis = this;
let actionParams = {
req: {
decodedParams: {}
}
};
actionParams.req.decodedParams = sanitizer.sanitizeParams(oThis.event);
Object.assign(actionParams.req.decodedParams, { apiVersion: apiVersions.internal });
if (oThis.event.resource === 'resize-image') {
actionParams.serviceToUse = '/app/services/ResizeAndUpload';
actionParams.errorCode = 'r_i_1';
actionParams.req.decodedParams.apiName = apiName.resizeAndUpload;
} else if (oThis.event.resource === 'compress-video') {
actionParams.serviceToUse = '/app/services/CompressVideo';
actionParams.errorCode = 'r_i_2';
actionParams.req.decodedParams.apiName = apiName.compressVideo;
} else if (oThis.event.resource === 'merge-video-segments') {
actionParams.serviceToUse = '/app/services/MergeVideoSegments';
actionParams.errorCode = 'r_i_3';
actionParams.req.decodedParams.apiName = apiName.mergeVideoSegments;
} else if (oThis.event.resource === 'extract-video-thumbnail') {
actionParams.serviceToUse = '/app/services/CreateThumbnail';
actionParams.errorCode = 'r_i_4';
actionParams.req.decodedParams.apiName = apiName.createVideoThumbnail;
}
return actionParams;
}
/**
* perform
*
* @return promise
**/
async perform() {
const oThis = this;
let actionParams = oThis.getResourceAndParamsForAction();
console.log('actionParams: ', actionParams);
return routeHelper.perform(
actionParams.req,
{ isLambda: true },
null,
actionParams.serviceToUse,
actionParams.errorCode,
null,
null,
null
);
}
}
exports.handler = async (event) => {
console.log('event: ', event);
let executor = new Executor(event);
let responseBody = await executor.perform();
// console.log('responseBody: ', responseBody);
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(responseBody)
};
};