김명주

Merge branch 'test' into 'master'

Test

Update detail information 
Add image file

See merge request !1
...@@ -5,6 +5,7 @@ var app=express(); ...@@ -5,6 +5,7 @@ var app=express();
5 const bodyParser=require('body-parser'); 5 const bodyParser=require('body-parser');
6 app.use(bodyParser.urlencoded({extended: false})); // URL 인코딩 안함 6 app.use(bodyParser.urlencoded({extended: false})); // URL 인코딩 안함
7 app.use(bodyParser.json()); // json 타입으로 파싱하게 설정 7 app.use(bodyParser.json()); // json 타입으로 파싱하게 설정
8 +app.use('/inf/result',express.static('metadata'));
8 9
9 app.set('views', __dirname + '/views'); 10 app.set('views', __dirname + '/views');
10 app.set('view engine', 'ejs'); 11 app.set('view engine', 'ejs');
...@@ -25,8 +26,37 @@ app.get("/inf/result",(req,res)=>{ ...@@ -25,8 +26,37 @@ app.get("/inf/result",(req,res)=>{
25 request.get(options, function(error, response, body){ 26 request.get(options, function(error, response, body){
26 if (!error && response.statusCode == 200) { 27 if (!error && response.statusCode == 200) {
27 var jsbody=JSON.parse(body); 28 var jsbody=JSON.parse(body);
28 - //res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'}); and res.end(body) 29 + var option2={
29 - res.render('inf_search_result', {aid:jsbody.accessId, name: jsbody.name, level: jsbody.level}); 30 + url: "https://api.nexon.co.kr/kart/v1.0/users/"+jsbody.accessId+"/matches?start_date=&end_date= &offset=0&limit=1&match_types=",
31 + headers:{Authorization: key}
32 + };
33 + request.get(option2, function(error, response, body){
34 + var match=JSON.parse(body);
35 + var tId=match.matches[0].matches[0].trackId;
36 + var kartId=match.matches[0].matches[0].player.kart;
37 + var mrank=match.matches[0].matches[0].player.matchRank;
38 + //한화라고 검색하면 아직 오류존재
39 + var players=match.matches[0].matches[0].playerCount;
40 + var stime=new Date(match.matches[0].matches[0].startTime.split('T')[0]+" "+match.matches[0].matches[0].startTime.split('T')[1]);
41 + var etime=new Date(match.matches[0].matches[0].endTime.split('T')[0]+" "+match.matches[0].matches[0].endTime.split('T')[1]);
42 + var diff=etime-stime
43 + var minute= Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
44 + var second = Math.floor((diff % (1000 * 60)) / 1000);
45 + var diff_time=minute + " : " + second;
46 + if(mrank=="99"){
47 + mrank="retire";
48 + diff_time="retire";
49 + }
50 + var ranking=mrank+" / "+players
51 +
52 + if (!error && response.statusCode == 200) {
53 + res.render('inf_search_result', {name: jsbody.name, level: jsbody.level, trackId: tId, kart:kartId,rank:ranking,time: diff_time});
54 + }
55 + else{
56 + res.status(response.statusCode).end();
57 + console.log('error = ' + response.statusCode);
58 + }
59 + });
30 } else { 60 } else {
31 res.status(response.statusCode).end(); 61 res.status(response.statusCode).end();
32 console.log('error = ' + response.statusCode); 62 console.log('error = ' + response.statusCode);
...@@ -38,6 +68,6 @@ app.get("/inf",(req,res)=>{ ...@@ -38,6 +68,6 @@ app.get("/inf",(req,res)=>{
38 res.render('inf_search_home'); 68 res.render('inf_search_home');
39 }); 69 });
40 70
41 -app.listen(8080,function(req,res){ 71 +app.listen("8080",function(req,res){
42 console.log('server listening at port no. 8080'); 72 console.log('server listening at port no. 8080');
43 }); 73 });
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 </head> 7 </head>
8 <body> 8 <body>
9 <input type="text" id="name" /> 9 <input type="text" id="name" />
10 - <input type="submit" onClick="location.href='result'" id="OK"/> 10 + <input type="submit" onClick="location.href='inf/result'" id="OK"/>
11 11
12 <script> 12 <script>
13 $("#OK").click(function(){ // OK 버튼 클릭하면 13 $("#OK").click(function(){ // OK 버튼 클릭하면
......
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 - <head> 3 +
4 +<head>
4 <meta charset="utf-8"> 5 <meta charset="utf-8">
5 <title>Hello World!</title> 6 <title>Hello World!</title>
6 <!-- 7 <!--
7 <link rel="stylesheet" href="/css/master.css" > 8 <link rel="stylesheet" href="/css/master.css" >
8 --> 9 -->
9 </head> 10 </head>
10 - <body> 11 +
11 - <h1>유저 정보 출력</h1><br> 12 +<body>
12 - <script> 13 + <script language="JavaScript">
14 + var name = '<%-name%>';
15 + var level = '<%-level%>';
16 + var trackId= '<%-trackId%>';
17 + var kart='<%-kart%>';
18 +
19 + document.write(name);
20 + document.write("\n");
21 +
22 + function Img() {
23 + var a = Math.floor(Math.random() * 9) + 1;
24 + return "main_character/" + a + ".png";
25 + }
26 + function Img2(){
27 + return "level/"+level+".png"
28 + }
29 + function Img3(){
30 + return "track/"+trackId+".png"
31 + }
32 + function Img4(){
33 + return "kart/"+kart+".png"
34 + }
13 </script> 35 </script>
14 - <span class="aid">USER ID<%= aid %></span><br> 36 + <img id="imgId" src="" width="135" height="100">
15 - <span class="name">NAME<%= name %></span><br> 37 + <script>document.getElementById("imgId").src = Img()</script>
16 - <span class="level">LEVEL<%= level %></span> 38 + <p>레벨</p>
39 + <img id="imgId2" src="">
40 + <script>document.getElementById("imgId2").src = Img2()</script>
41 + <H1>――――――――――――――――경기 정보――――――――――――――</H1>
42 + <p>등수</p>
43 + <span class="rank"><%= rank %></span>
44 + <p>주행 시간</p>
45 + <span class="time"><%= time %></span>
46 + <p>트랙정보</p>
47 + <img id="imgId3" src="">
48 + <script>document.getElementById("imgId3").src = Img3()</script>
49 + <p>카트정보</p>
50 + <img id="imgId4" src="" width="135" height="100">
51 + <script>document.getElementById("imgId4").src = Img4()</script>
52 +
53 +
54 +</body>
17 55
18 - </body>
19 </html> 56 </html>
...\ No newline at end of file ...\ No newline at end of file
......