-
Notifications
You must be signed in to change notification settings - Fork 0
/
editImage.js
47 lines (41 loc) · 1.25 KB
/
editImage.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
"use strict";
const AWS = require("aws-sdk");
const { updateImageIfExists } = require("./utils/apis");
const { respond, API_IDENTIFIERS } = require("./utils/helpers");
const config = require("./config/config.json");
module.exports.process = (event, context, callback) => {
const { currentCategory, newCategory, description, updateTime } = JSON.parse(
event.body
);
const dynamoDB = new AWS.DynamoDB({
accessKeyId: config.AWS_ACCESS_KEY_ID,
secretAccessKey: config.AWS_SECRET_ACCESS_KEY,
region: config.AWS_REGION,
apiVersion: "2012-08-10",
});
let executionCount = 0;
async function updateImageMetadata() {
executionCount++;
try {
await updateImageIfExists(
dynamoDB,
currentCategory,
newCategory,
description,
updateTime
);
respond(API_IDENTIFIERS.EDIT_IMAGE.name, true, callback);
} catch (error) {
console.error(
`${API_IDENTIFIERS.EDIT_IMAGE.failure} with error ${error} with executionCount `,
executionCount
);
if (executionCount < Math.round(config.MAX_EXECUTION_COUNT)) {
updateImageMetadata();
} else {
respond(API_IDENTIFIERS.EDIT_IMAGE.name, false, callback);
}
}
}
updateImageMetadata();
};