Showing
1 changed file
with
254 additions
and
0 deletions
router/test.js
0 → 100644
1 | +module.exports = function(app){ | ||
2 | + | ||
3 | + var request = require("request"); | ||
4 | + var urlenconde = require('urlencode'); | ||
5 | + var apikey = "RGAPI-2ac4afdc-e474-467b-ad1f-e08d559bf95b"//api | ||
6 | + | ||
7 | + var profileIconId; //아이콘 번호 | ||
8 | + var revisionDate; //수정날짜 | ||
9 | + var puuid; | ||
10 | + var id; //소환사ID | ||
11 | + var accountId; //계정Id | ||
12 | + var name; //소환사 이름 | ||
13 | + var summonerLevel; //소환사 | ||
14 | + var rotation_champ = new Array(); | ||
15 | + | ||
16 | + app.get('/', function(req, res) { | ||
17 | + res.render('main', { title: 'Your TFT.GG?' }); | ||
18 | + }); | ||
19 | + | ||
20 | + app.get('/search/:username/', function(req, res, next){ | ||
21 | + //롤 api url | ||
22 | + name = req.params.username; | ||
23 | + var nameUrl = "https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/" + urlenconde(name)+"?api_key="+ apikey; | ||
24 | + request(nameUrl,function(error,response,body){ | ||
25 | + | ||
26 | + // 요청에 대한 응답이 성공적으로 왔는지 검사. | ||
27 | + // status code가 200이 아니면 오류가 있었던 것으로 간주하고 함수 종료. | ||
28 | + | ||
29 | + if (response.statusCode != 200) { | ||
30 | + console.log('Error with response code22 ', response.statusCode); | ||
31 | + res.end(); | ||
32 | + return; | ||
33 | + } | ||
34 | + | ||
35 | + var info_summoner_json = JSON.parse(body); | ||
36 | + | ||
37 | + accountId = info_summoner_json["accountId"]; | ||
38 | + id = info_summoner_json["id"]; | ||
39 | + puuid = info_summoner_json["puuid"]; | ||
40 | + summoner = info_summoner_json["name"]; | ||
41 | + profileIconId = info_summoner_json["profileIconId"]; | ||
42 | + summonerLevel = info_summoner_json["summonerLevel"]; | ||
43 | + revisionDate = info_summoner_json["revisionDate"]; | ||
44 | + | ||
45 | + var champUrl = "https://kr.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/" + urlenconde(id) + "?api_key=" + apikey; | ||
46 | + request(champUrl,function(error,response,body){ | ||
47 | + var trait_id=new Array(); | ||
48 | + var char_id=new Array(); | ||
49 | + var char_img=new Array(); | ||
50 | + var trait_img=new Array(); | ||
51 | + var info_champ_json = JSON.parse(body); | ||
52 | + var champ_point = new Array(); | ||
53 | + var champ_id = new Array(); | ||
54 | + var champ_name = new Array(); | ||
55 | + var rotation_name = new Array(); | ||
56 | + var champ_pic = new Array(); | ||
57 | + var rotation_pic =new Array(); | ||
58 | + var champions_length = Object.keys(info_champ_json).length; | ||
59 | + | ||
60 | + //console.log("\n\ninfo_champ_json\n\n", info_champ_json); | ||
61 | + | ||
62 | + // status code가 200이 아니면 종료. | ||
63 | + | ||
64 | + | ||
65 | + var rotationUrl = "https://kr.api.riotgames.com/lol/platform/v3/champion-rotations?api_key="+apikey; | ||
66 | + request(rotationUrl,function(error,response,body){ | ||
67 | + var info_rotation = JSON.parse(body); | ||
68 | + var keys = Object.keys(info_rotation); | ||
69 | + | ||
70 | + var staticUrl = "http://ddragon.leagueoflegends.com/cdn/9.23.1/data/en_US/champion.json"; | ||
71 | + request(staticUrl,function(error,response,body){ | ||
72 | + var info_static_champ_json = JSON.parse(body); | ||
73 | + var champion = info_static_champ_json["data"]; | ||
74 | + | ||
75 | + var userLeagueUrl = "https://kr.api.riotgames.com/tft/league/v1/entries/by-summoner/"+ urlenconde(id)+"?api_key=" + apikey; | ||
76 | + request(userLeagueUrl,function(error,response,body){ | ||
77 | + var info_user_league_json = JSON.parse(body); | ||
78 | + //console.log("userLeagueUrl:", userLeagueUrl); | ||
79 | + if(info_user_league_json[0] != null){ | ||
80 | + var leagueId = info_user_league_json[0]["leagueId"]; | ||
81 | + var wins = info_user_league_json[0]["wins"]; | ||
82 | + var losses = info_user_league_json[0]["losses"]; | ||
83 | + var leagueName = info_user_league_json[0]["leagueName"] | ||
84 | + var tier = info_user_league_json[0]["tier"]; | ||
85 | + var rank = info_user_league_json[0]["rank"]; | ||
86 | + var leaguePoints = info_user_league_json[0]["leaguePoints"]; | ||
87 | + var img_tier; | ||
88 | + if(tier == "MASTER"){ | ||
89 | + img_tier = "https://i.imgur.com/nvQjonh.png"; | ||
90 | + }else if(tier == "CHALLENGER"){ | ||
91 | + img_tier = "https://i.imgur.com/sbK1Edj.png"; | ||
92 | + }else if(tier == "DIAMOND"){ | ||
93 | + img_tier = "https://i.imgur.com/5VBu8PF.png" | ||
94 | + }else if(tier == "PLATINUM"){ | ||
95 | + img_tier = "https://i.imgur.com/Eqi6858.png" | ||
96 | + }else if(tier == "GRANDMASTER"){ | ||
97 | + img_tier = "https://i.imgur.com/mcEhz1o.png" | ||
98 | + }else if(tier == "GOLD"){ | ||
99 | + img_tier = "https://i.imgur.com/Ec4hPuO.png" | ||
100 | + }else if(tier == "SILVER"){ | ||
101 | + img_tier = "https://i.imgur.com/GKnPu7s.png" | ||
102 | + }else if(tier == "BRONZE"){ | ||
103 | + img_tier ="https://i.imgur.com/TPZVXIr.png" | ||
104 | + }else{ | ||
105 | + img_tier = "https://i.imgur.com/kcdoC4r.png" | ||
106 | + } | ||
107 | + } | ||
108 | + var userMatchUrl = "https://asia.api.riotgames.com/tft/match/v1/matches/by-puuid/"+urlenconde(puuid)+"/ids?start=0&count=20&api_key="+apikey; | ||
109 | + request(userMatchUrl,function(error,response,body){ | ||
110 | + var info_match=JSON.parse(body); | ||
111 | + var userGameUrl = "https://asia.api.riotgames.com/tft/match/v1/matches/" + urlenconde(info_match[0]) + "?api_key=" +apikey; | ||
112 | + | ||
113 | + request(userGameUrl,function(error,response,body){ | ||
114 | + var info_game = JSON.parse(body); | ||
115 | + | ||
116 | + for(var j=0;j<8;j++){ | ||
117 | + if(info_game["info"]["participants"][j]["puuid"]==puuid){ | ||
118 | + for(var k=0;k<info_game["info"]["participants"][j]["traits"].length;k++){ | ||
119 | + trait_id[k]=info_game["info"]["participants"][j]["traits"][k]["name"].substr(5,); | ||
120 | + } | ||
121 | + for(var k=0;k<info_game["info"]["participants"][j]["units"].length;k++){ | ||
122 | + char_id[k]=info_game["info"]["participants"][j]["units"][k]["character_id"].substr(5,); | ||
123 | + } | ||
124 | + | ||
125 | + } | ||
126 | + } | ||
127 | + for(var i=0;i<char_id.length;i++){ | ||
128 | + if(char_id[i]=="Sejuani"){ | ||
129 | + char_img[i]="https://cdn.lolchess.gg/upload/images/champions/Sejuani_1653029956.png"; | ||
130 | + } | ||
131 | + else if(char_id[i]=="Ezreal"){ | ||
132 | + char_img[i]="https://cdn.lolchess.gg/upload/images/champions/Ezreal_1653030256.png"; | ||
133 | + } | ||
134 | + else if(char_id[i]=="Twitch"){ | ||
135 | + char_img[i]="https://cdn.lolchess.gg/upload/images/champions/Twitch_1653030423.png"; | ||
136 | + } | ||
137 | + else if(char_id[i]=="Varus"){ | ||
138 | + char_img[i]="https://cdn.lolchess.gg/upload/images/champions/Varus_1653029781.png"; | ||
139 | + } | ||
140 | + else if(char_id[i]=="DragonGuild"){ | ||
141 | + char_img[i]="https://cdn.lolchess.gg/upload/images/champions/Zippy_1664508034-Zippy_1661407350-tft7_zippy_square.tft_set7_stage2.png"; | ||
142 | + } | ||
143 | + else if(char_id[i]=="Hecarim"){ | ||
144 | + char_img[i]="https://cdn.lolchess.gg/upload/images/champions/Hecarim_1653030476.png"; | ||
145 | + } | ||
146 | + else if(char_id[i]=="Jayce"){ | ||
147 | + char_img[i]="https://cdn.lolchess.gg/upload/images/champions/Jayce_1661160949-Jayce.jpg"; | ||
148 | + } | ||
149 | + | ||
150 | + } | ||
151 | + | ||
152 | + | ||
153 | + for(var i=0;i<trait_id.length;i++){ | ||
154 | + | ||
155 | + if(trait_id[i]=="Astral"){ | ||
156 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Astral_normal_1658472777-astral.svg"; | ||
157 | + } | ||
158 | + else if(trait_id[i]=="Guild"){ | ||
159 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Guild_normal_1658472708-guild.svg" | ||
160 | + } | ||
161 | + else if(trait_id[i]=="Jade"){ | ||
162 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Jade_normal_1658472802-jade.svg" | ||
163 | + } | ||
164 | + else if(trait_id[i]=="Mirage"){ | ||
165 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Mirage_normal_1658472829-mirage.svg" | ||
166 | + } | ||
167 | + else if(trait_id[i]=="Ragewing"){ | ||
168 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Ragewing_normal_1658472786-ragewing.svg" | ||
169 | + } | ||
170 | + else if(trait_id[i]=="Revel"){ | ||
171 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Revel_normal_1658472846-revel.svg" | ||
172 | + } | ||
173 | + else if(trait_id[i]=="Scalescorn"){ | ||
174 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Scalescorn_normal_1658472793-scalescorn.svg" | ||
175 | + } | ||
176 | + else if(trait_id[i]=="Shimmerscale"){ | ||
177 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Shimmerscale_normal_1658472811-shimmerscale.svg" | ||
178 | + } | ||
179 | + else if(trait_id[i]=="Assasin"){ | ||
180 | + trait_img[i]="https://cdn.lolchess.gg/images/tft/traiticons-darken/7.0/assassin.svg" | ||
181 | + } | ||
182 | + else if(trait_id[i]=="Cavalier"){ | ||
183 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Cavalier_normal_1658472863-cavalier.svg" | ||
184 | + } | ||
185 | + else if(trait_id[i]=="Dragon"){ | ||
186 | + trait_img[i]="https://cdn.lolchess.gg/images/tft/traiticons-darken/7.0/dragons.svg" | ||
187 | + } | ||
188 | + else if(trait_id[i]=="Shapeshifter"){ | ||
189 | + trait_img[i]="https://cdn.lolchess.gg/images/tft/traiticons-darken/7.0/shapeshifter.svg" | ||
190 | + } | ||
191 | + else if(trait_id[i]=="Swiftshot"){ | ||
192 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Swiftshot_normal_1658472880-swiftshot.svg" | ||
193 | + } | ||
194 | + else if(trait_id[i]=="Tempest"){ | ||
195 | + trait_img[i]="https://cdn.lolchess.gg/upload/images/traits/Tempest_normal_1658472854-tempest.svg" | ||
196 | + } | ||
197 | + } | ||
198 | + const defaultMMR = [ | ||
199 | + {"mmr" : 900, "tier" : "iron", "rank": 4}, | ||
200 | + {"mmr" : 950, "tier" : "iron", "rank": 3}, | ||
201 | + {"mmr" : 1000, "tier" : "iron", "rank": 2}, | ||
202 | + {"mmr" : 1050, "tier" : "iron", "rank": 1}, | ||
203 | + { "mmr" : 1100, "tier" : "bronze", "rank": 4 }, | ||
204 | + { "mmr" : 1150, "tier" : "bronze", "rank": 3 }, | ||
205 | + { "mmr" : 1200, "tier" : "bronze", "rank": 2 }, | ||
206 | + { "mmr" : 1250, "tier" : "bronze", "rank": 1 }, | ||
207 | + { "mmr" : 1300, "tier" : "silver", "rank": 4 }, | ||
208 | + { "mmr" : 1350, "tier" : "silver", "rank": 3 }, | ||
209 | + { "mmr" : 1400, "tier" : "silver", "rank": 2 }, | ||
210 | + { "mmr" : 1450, "tier" : "silver", "rank": 1 }, | ||
211 | + { "mmr" : 1500, "tier" : "gold", "rank": 4 }, | ||
212 | + { "mmr" : 1550, "tier" : "gold", "rank": 3 }, | ||
213 | + { "mmr" : 1600, "tier" : "gold", "rank": 2 }, | ||
214 | + { "mmr" : 1650, "tier" : "gold", "rank": 1 }, | ||
215 | + { "mmr" : 1700, "tier" : "platinum", "rank": 4 }, | ||
216 | + { "mmr" : 1750, "tier" : "platinum", "rank": 3 }, | ||
217 | + { "mmr" : 1800, "tier" : "platinum", "rank": 2 }, | ||
218 | + { "mmr" : 1850, "tier" : "platinum", "rank": 1 }, | ||
219 | + { "mmr" : 1900, "tier" : "diamond", "rank": 4 }, | ||
220 | + { "mmr" : 1950, "tier" : "diamond", "rank": 3 }, | ||
221 | + { "mmr" : 2000, "tier" : "diamond", "rank": 2 }, | ||
222 | + { "mmr" : 2050, "tier" : "diamond", "rank": 1 }, | ||
223 | + { "mmr" : 2100, "tier" : "master", "rank": 1 }, | ||
224 | + { "mmr" : 2700, "tier" : "challenger", "rank": 1 }, | ||
225 | + ] | ||
226 | + | ||
227 | + res.render('index', { title: req.params.username , | ||
228 | + c_imgtrait: trait_img, | ||
229 | + c_imgchar: char_img, | ||
230 | + c_id: champ_id, | ||
231 | + c_name: champ_name, | ||
232 | + c_point: champ_point, | ||
233 | + c_pic: champ_pic, | ||
234 | + c_rotation : rotation_pic, | ||
235 | + c_summoner: summoner, | ||
236 | + c_wins: wins, | ||
237 | + c_losses: losses, | ||
238 | + c_tier: tier, | ||
239 | + c_imgtier: img_tier, | ||
240 | + c_rank: rank, | ||
241 | + c_leaguePoint: leaguePoints | ||
242 | + }); | ||
243 | + | ||
244 | + }); | ||
245 | + }); | ||
246 | + | ||
247 | + | ||
248 | + }); | ||
249 | + }); | ||
250 | + }); | ||
251 | + }); | ||
252 | + }); | ||
253 | + }); | ||
254 | +}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment