seungmin lee

removed frontend's aws request

......@@ -15,8 +15,8 @@ app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.json({limit : "50mb"}));
app.use(express.urlencoded({ limit:"50mb",extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
......
......@@ -23,6 +23,11 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"atob": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg=="
},
"aws-sdk": {
"version": "2.791.0",
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.791.0.tgz",
......
......@@ -7,6 +7,7 @@
},
"dependencies": {
"@tensorflow-models/blazeface": "0.0.5",
"atob": "^2.1.2",
"aws-sdk": "^2.791.0",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
......
// AWS.config.credentials = new AWS.Credentials("AKIATDD4YZYTAHUYQO7J","xUnIHtJOd/KrEw4HWLXs7JBtg2H2J1+MQfBIe6hj")
// AWS.config.update({region: 'ap-northeast-2'});
\ No newline at end of file
......@@ -65,33 +65,45 @@ async function AWS_req(img_byte){
},
MaxFaces: 5
};
rekognition.searchFacesByImage(params, function(err, data){
if (err) {
console.log(err, err.stack); // an error occurred
alert("AWS Not configured. Check /pubilc/javascripts/aws_setup.js");
window.location.href = '/';
}
post_data = {
"result": false,
"type" : element.value,
"landing": "false",
"image":img_byte
}
console.log(img_byte)
redirectPost("/use",post_data)
// rekognition.searchFacesByImage(params, function(err, data){
// if (err) {
// console.log(err, err.stack); // an error occurred
// alert("AWS Not configured. Check /pubilc/javascripts/aws_setup.js");
// // window.location.href = '/';
// }
else console.log(data); // successful response
if (data.FaceMatches.length>0){
post_data = {
"result": true,
"type" : element.value,
"landing": "false"
}
}
else{
post_data = {
"result": false,
"type" : element.value,
"landing": "false"
}
redirectPost("/use",post_data)
}
// else console.log(data); // successful response
// if (data.FaceMatches.length>0){
// post_data = {
// "result": true,
// "type" : element.value,
// "landing": "false",
// "image":img_byte
// }
// // redirectPost("/use",post_data)
// }
// else{
// post_data = {
// "result": false,
// "type" : element.value,
// "landing": "false",
// "image":img_byte
// }
// console.log('me!')
// // redirectPost("/use",post_data)
// }
}
)
// }
// )
}
......@@ -157,7 +169,7 @@ function onClick(){
ua[i] = enc_data.charCodeAt(i);
}
// console.log(ua)
AWS_req(ua)
AWS_req(dataURL)
}
const setupPage = async () => {
......
var express = require("express");
var router = express.Router();
var AWS = require("aws-sdk");
var fs = require("fs");
var atob = require('atob');
AWS.config.loadFromPath("./config.json");
var rekognition = new AWS.Rekognition();
const { exec } = require("child_process");
router.post("/", function (req, res, next) {
console.log(req.body)
if(req.body.landing == "true"){
if (req.body.landing == "true") {
res.render('use', { method: req.body.type })
}
else{
exec(
"python action.py " +
req.body.type,
(error, stdout, stderr) => {
if (error) {
res.render("error",{message : "Error", title:"No action.py", content:"make sure you have cloned github repository" });
return;
else {
image = req.body.image
// console.log(image)
// var img_arr = req.body.image.split(',').map(function(item) {
// return parseInt(item, 10);
// });
// console.log(img_arr)
// enc_data = Buffer.from(image.split("data:image/png;base64,")[1], 'base64').toString('ascii')
if(image[11]=='p')
enc_data = atob(image.split("data:image/png;base64,")[1])
else if(image[11]=='j')
enc_data = atob(image.split("data:image/jpeg;base64,")[1])
var length = enc_data.length;
imageBytes = new ArrayBuffer(length);
var ua = new Uint8Array(imageBytes);
for (var i = 0; i < length; i++) {
ua[i] = enc_data.charCodeAt(i);
}
// console.log(imageBytes)
var params = {
CollectionId: "6jj2",
FaceMatchThreshold: 95,
Image: {
Bytes: imageBytes
},
MaxFaces: 5
};
rekognition.searchFacesByImage(params, function (err, data) {
if (err) {
console.log(err, err.stack);
}
else {
if (data.FaceMatches.length>0){
res.redirect("/");
}
if (stderr) {
res.render("error",{message : "Error", title:"No action.py", content:"make sure you have cloned github repository" });
return;
else{
// todo 잠금 페이지로 이동.
}
console.log(`stdout: ${stdout}`);
res.render("action");
}
);
});
}
});
......
<h1><%= message %></h1>
<h2><%= title %></h2>
<pre><%= content %></pre>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>
<a href="/"> go back to home </a>
......