index.js
1.16 KB
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
var express = require("express");
var router = express.Router();
function makeid(length) {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var AWS = require("aws-sdk");
AWS.config.loadFromPath("./config.json");
var rekognition = new AWS.Rekognition();
/* GET home page. */
router.get("/", function (req, res, next) {
var collectionID = makeid(8);
var params = {
CollectionId: collectionID,
};
rekognition.createCollection(params, function (err, data) {
if (err) console.log(err, err.stack);
// an error occurred
else console.log(data); // successful response
});
console.log(collectionID);
res.render("index", {
title: "AI Screensaver",
error: "",
collection: collectionID,
});
});
router.post("/", function (req, res, next) {
console.log(req.body.collection);
res.render("index", {
title: "AI Screensaver",
error: "",
collection: req.body.collection,
});
});
module.exports = router;