Showing
1 changed file
with
33 additions
and
3 deletions
... | @@ -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 | ... | ... |
-
Please register or login to post a comment