Toggle navigation
Toggle navigation
This project
Loading...
Sign in
seungmin lee
/
OSS2020-2_Screensaver
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
seungmin lee
2020-12-04 23:43:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b7d65c93a6eb398ab1c4a52a30537b99420bca86
b7d65c93
1 parent
26bd8d38
removed frontend's aws request
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
91 additions
and
46 deletions
screensaver/app.js
screensaver/package-lock.json
screensaver/package.json
screensaver/public/javascripts/aws_setup.js
screensaver/public/javascripts/index.js
screensaver/routes/use.js
screensaver/views/error.ejs
screensaver/app.js
View file @
b7d65c9
...
...
@@ -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"
)));
...
...
screensaver/package-lock.json
View file @
b7d65c9
...
...
@@ -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"
,
...
...
screensaver/package.json
View file @
b7d65c9
...
...
@@ -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"
,
...
...
screensaver/public/javascripts/aws_setup.js
deleted
100644 → 0
View file @
26bd8d3
// AWS.config.credentials = new AWS.Credentials("AKIATDD4YZYTAHUYQO7J","xUnIHtJOd/KrEw4HWLXs7JBtg2H2J1+MQfBIe6hj")
// AWS.config.update({region: 'ap-northeast-2'});
\ No newline at end of file
screensaver/public/javascripts/index.js
View file @
b7d65c9
...
...
@@ -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
()
=>
{
...
...
screensaver/routes/use.js
View file @
b7d65c9
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"
);
}
);
}
);
}
});
...
...
screensaver/views/error.ejs
View file @
b7d65c9
<h1><%= message %></h1>
<h2><%= title %></h2>
<pre><%= content %></pre>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>
<a href="/"> go back to home </a>
...
...
Please
register
or
login
to post a comment