Showing
3 changed files
with
49 additions
and
37 deletions
... | @@ -26,6 +26,7 @@ app.post('/test/result',test.result_post); | ... | @@ -26,6 +26,7 @@ app.post('/test/result',test.result_post); |
26 | 26 | ||
27 | /* inf */ | 27 | /* inf */ |
28 | app.get('/search',search.home_get); | 28 | app.get('/search',search.home_get); |
29 | +app.post('/search',search.home_post); | ||
29 | app.get('/search/result',search.result_get); | 30 | app.get('/search/result',search.result_get); |
30 | app.post('/search/result',search.result_post); | 31 | app.post('/search/result',search.result_post); |
31 | 32 | ... | ... |
1 | var key="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50X2lkIjoiMjAxNjMxMTYzIiwiYXV0aF9pZCI6IjIiLCJ0b2tlbl90eXBlIjoiQWNjZXNzVG9rZW4iLCJzZXJ2aWNlX2lkIjoiNDMwMDExMzkzIiwiWC1BcHAtUmF0ZS1MaW1pdCI6IjUwMDoxMCIsIm5iZiI6MTYzNDMwMTE0NCwiZXhwIjoxNjQ5ODUzMTQ0LCJpYXQiOjE2MzQzMDExNDR9.EEWMly4HZG_DY-aleMtDFVOOmbWl8uVmG1tHVM3c-BE" | 1 | var key="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50X2lkIjoiMjAxNjMxMTYzIiwiYXV0aF9pZCI6IjIiLCJ0b2tlbl90eXBlIjoiQWNjZXNzVG9rZW4iLCJzZXJ2aWNlX2lkIjoiNDMwMDExMzkzIiwiWC1BcHAtUmF0ZS1MaW1pdCI6IjUwMDoxMCIsIm5iZiI6MTYzNDMwMTE0NCwiZXhwIjoxNjQ5ODUzMTQ0LCJpYXQiOjE2MzQzMDExNDR9.EEWMly4HZG_DY-aleMtDFVOOmbWl8uVmG1tHVM3c-BE" |
2 | -var chname; | 2 | +var request=require('request'); |
3 | -var userId; | 3 | +var userId=[]; |
4 | -var username; | 4 | +var username=[]; |
5 | -var kart_level; | ||
6 | exports.home_get=function(req,res){ | 5 | exports.home_get=function(req,res){ |
7 | res.render('search_home'); | 6 | res.render('search_home'); |
8 | }; | 7 | }; |
9 | - | 8 | +exports.home_post=function(req,res){ |
10 | - | 9 | + var chname=encodeURIComponent(req.body.test); |
11 | -exports.result_post=function(req,res){ | ||
12 | - chname=encodeURIComponent(req.body.test); | ||
13 | var api_url='https://api.nexon.co.kr/kart/v1.0/users/nickname/'+chname; | 10 | var api_url='https://api.nexon.co.kr/kart/v1.0/users/nickname/'+chname; |
14 | - var request=require('request'); | ||
15 | var options={ | 11 | var options={ |
16 | url: api_url, | 12 | url: api_url, |
17 | headers:{Authorization: key} | 13 | headers:{Authorization: key} |
... | @@ -19,9 +15,8 @@ exports.result_post=function(req,res){ | ... | @@ -19,9 +15,8 @@ exports.result_post=function(req,res){ |
19 | request.get(options, function(error, response, body){ | 15 | request.get(options, function(error, response, body){ |
20 | if (!error && response.statusCode == 200) { | 16 | if (!error && response.statusCode == 200) { |
21 | var jsbody=JSON.parse(body); | 17 | var jsbody=JSON.parse(body); |
22 | - userId=jsbody.accessId; | 18 | + userId.push(jsbody.accessId); |
23 | - username=jsbody.name; | 19 | + username.push(jsbody.name); |
24 | - kart_level=jsbody.level; | ||
25 | res.send(JSON.stringify(response.statusCode)); | 20 | res.send(JSON.stringify(response.statusCode)); |
26 | } | 21 | } |
27 | else { | 22 | else { |
... | @@ -30,9 +25,13 @@ exports.result_post=function(req,res){ | ... | @@ -30,9 +25,13 @@ exports.result_post=function(req,res){ |
30 | }); | 25 | }); |
31 | } | 26 | } |
32 | 27 | ||
28 | +exports.result_post=function(req,res){ | ||
29 | + | ||
30 | +} | ||
31 | + | ||
33 | exports.result_get = function (req, res) { | 32 | exports.result_get = function (req, res) { |
34 | - var api_url="https://api.nexon.co.kr/kart/v1.0/users/" + userId + "/matches?start_date=&end_date= &offset=0&limit=10&match_types=7b9f0fd5377c38514dbb78ebe63ac6c3b81009d5a31dd569d1cff8f005aa881a"; | 33 | + var api_url="https://api.nexon.co.kr/kart/v1.0/users/" + userId[0] + "/matches?start_date=&end_date= &offset=0&limit=10&match_types=7b9f0fd5377c38514dbb78ebe63ac6c3b81009d5a31dd569d1cff8f005aa881a"; |
35 | - var request=require('request'); | 34 | + userId.splice(0,1); |
36 | var options = { | 35 | var options = { |
37 | //개인전만 검색하는 것임 | 36 | //개인전만 검색하는 것임 |
38 | url: api_url, | 37 | url: api_url, |
... | @@ -41,7 +40,9 @@ exports.result_get = function (req, res) { | ... | @@ -41,7 +40,9 @@ exports.result_get = function (req, res) { |
41 | request.get(options, function (error, response, body) { | 40 | request.get(options, function (error, response, body) { |
42 | if (!error && response.statusCode == 200) { | 41 | if (!error && response.statusCode == 200) { |
43 | var match = JSON.parse(body); | 42 | var match = JSON.parse(body); |
44 | - res.render('search_result', { name: username, level: kart_level, body: JSON.stringify(match) }); | 43 | + var nickname=username[0]; |
44 | + username.splice(0,1); | ||
45 | + res.render('search_result', { name: nickname, body: JSON.stringify(match) }); | ||
45 | } | 46 | } |
46 | else{ | 47 | else{ |
47 | res.send("error :" + response.statusCode); | 48 | res.send("error :" + response.statusCode); | ... | ... |
1 | -var vec; | 1 | +var vectemp=[]; |
2 | -var keyword=[]; | 2 | +var keytemp=[]; |
3 | - | ||
4 | exports.home_get=function(req,res){ | 3 | exports.home_get=function(req,res){ |
5 | res.render('test_home'); | 4 | res.render('test_home'); |
6 | }; | 5 | }; |
6 | +exports.result_post = function (req, res) { | ||
7 | + var vec = req.body.test; | ||
8 | + if (vec == null) { | ||
9 | + res.status(404).send("Not Found"); | ||
10 | + } | ||
11 | + else { | ||
12 | + var item = ["empty", "추억", "empty", "신중함", "안정적", "empty", "열정", "책임감", "아이템", "스피드", "믿음직", "호기심", "헌신적", "자유로움"]; | ||
13 | + var keyword = []; | ||
14 | + for (var i = 1; i < vec.length; i++) { | ||
15 | + if (i % 2 != 0) { | ||
16 | + if (vec[i] == "1") { | ||
17 | + keyword.push(item[i - 1]); | ||
18 | + } | ||
19 | + else { | ||
20 | + keyword.push(item[i]); | ||
21 | + } | ||
22 | + } | ||
23 | + } | ||
24 | + vectemp.push(vec); | ||
25 | + keytemp.push(keyword); | ||
26 | + res.send("success"); | ||
27 | + } | ||
28 | +}; | ||
7 | 29 | ||
8 | exports.result_get=function(req,res){ | 30 | exports.result_get=function(req,res){ |
9 | var temp=""; | 31 | var temp=""; |
10 | - for(var i=0; i<vec.length; i++){ | 32 | + for(var i=0; i<vectemp[0].length; i++){ |
11 | if(i!=2 && i!=3 && i!=4 && i!=5 && i!=10 && i!=11) | 33 | if(i!=2 && i!=3 && i!=4 && i!=5 && i!=10 && i!=11) |
12 | - temp+=vec[i]; | 34 | + temp+=vectemp[0][i]; |
13 | } | 35 | } |
36 | + console.log(vectemp); | ||
37 | + vectemp.splice(0,1); | ||
14 | var fs=require('fs'); | 38 | var fs=require('fs'); |
15 | var url="metadata/kart_find"+temp+"/"; | 39 | var url="metadata/kart_find"+temp+"/"; |
16 | var testFolder="views/metadata/kart_find"+temp; | 40 | var testFolder="views/metadata/kart_find"+temp; |
17 | fs.readdir(testFolder, function(error, list){ | 41 | fs.readdir(testFolder, function(error, list){ |
18 | var rand=Math.floor(Math.random()*list.length); | 42 | var rand=Math.floor(Math.random()*list.length); |
19 | - res.render('test_result',{url:url,body:list[rand],keyword:keyword}); | 43 | + var keyw=keytemp[0]; |
44 | + keytemp.splice(0,1); | ||
45 | + res.render('test_result',{url:url,body:list[rand],keyword:keyw}); | ||
20 | }); | 46 | }); |
21 | }; | 47 | }; |
... | \ No newline at end of file | ... | \ No newline at end of file |
22 | - | ||
23 | -exports.result_post=function(req,res){ | ||
24 | - vec=req.body.test; | ||
25 | - var item=["empty", "추억", "empty", "신중함","안정적","empty","열정","책임감","아이템","스피드","믿음직","호기심","헌신적","자유로움"]; | ||
26 | - keyword=[]; | ||
27 | - for(var i=1; i<vec.length; i++){ | ||
28 | - if(i%2!=0){ | ||
29 | - if(vec[i]=="1"){ | ||
30 | - keyword.push(item[i-1]); | ||
31 | - } | ||
32 | - else{ | ||
33 | - keyword.push(item[i]); | ||
34 | - } | ||
35 | - } | ||
36 | - } | ||
37 | -}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment