Showing
6 changed files
with
67 additions
and
5 deletions
... | @@ -6,6 +6,6 @@ let routes = require('./routes'); | ... | @@ -6,6 +6,6 @@ let routes = require('./routes'); |
6 | app.use(bodyParser.urlencoded({ extended: false })); | 6 | app.use(bodyParser.urlencoded({ extended: false })); |
7 | app.use(bodyParser.json()); | 7 | app.use(bodyParser.json()); |
8 | 8 | ||
9 | -app.get('/api/home', routes.home); | 9 | +app.get('/api/character', routes.character.getCharacter); |
10 | 10 | ||
11 | let server = app.listen(80); | 11 | let server = app.listen(80); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -84,6 +84,14 @@ | ... | @@ -84,6 +84,14 @@ |
84 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", | 84 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", |
85 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" | 85 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" |
86 | }, | 86 | }, |
87 | + "axios": { | ||
88 | + "version": "0.19.2", | ||
89 | + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", | ||
90 | + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", | ||
91 | + "requires": { | ||
92 | + "follow-redirects": "1.5.10" | ||
93 | + } | ||
94 | + }, | ||
87 | "balanced-match": { | 95 | "balanced-match": { |
88 | "version": "1.0.0", | 96 | "version": "1.0.0", |
89 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", | 97 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", |
... | @@ -444,6 +452,24 @@ | ... | @@ -444,6 +452,24 @@ |
444 | "unpipe": "~1.0.0" | 452 | "unpipe": "~1.0.0" |
445 | } | 453 | } |
446 | }, | 454 | }, |
455 | + "follow-redirects": { | ||
456 | + "version": "1.5.10", | ||
457 | + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", | ||
458 | + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", | ||
459 | + "requires": { | ||
460 | + "debug": "=3.1.0" | ||
461 | + }, | ||
462 | + "dependencies": { | ||
463 | + "debug": { | ||
464 | + "version": "3.1.0", | ||
465 | + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", | ||
466 | + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", | ||
467 | + "requires": { | ||
468 | + "ms": "2.0.0" | ||
469 | + } | ||
470 | + } | ||
471 | + } | ||
472 | + }, | ||
447 | "forwarded": { | 473 | "forwarded": { |
448 | "version": "0.1.2", | 474 | "version": "0.1.2", |
449 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", | 475 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", | ... | ... |
... | @@ -9,6 +9,7 @@ | ... | @@ -9,6 +9,7 @@ |
9 | "author": "", | 9 | "author": "", |
10 | "license": "ISC", | 10 | "license": "ISC", |
11 | "dependencies": { | 11 | "dependencies": { |
12 | + "axios": "^0.19.2", | ||
12 | "express": "^4.17.1", | 13 | "express": "^4.17.1", |
13 | "http": "0.0.1-security", | 14 | "http": "0.0.1-security", |
14 | "nodemon": "^2.0.4" | 15 | "nodemon": "^2.0.4" | ... | ... |
app/node/routes/character.js
0 → 100644
1 | +axios = require('axios'); | ||
2 | + | ||
3 | +const crwalCharacterCode = async function(nickname) { | ||
4 | + try { | ||
5 | + const resp = await axios.get("https://maplestory.nexon.com/Ranking/World/Total?c=" + encodeURI(nickname)); | ||
6 | + | ||
7 | + const regex = new RegExp(`<dt><a href=\\"\\/Common\\/Character\\/Detail\\/[^\\?]+?\\?p=(.+?)\\"\\s+target=.+?\\/>${nickname}<\\/a><\\/dt>`); | ||
8 | + const regexResult = regex.exec(resp.data); | ||
9 | + | ||
10 | + if (!regexResult) | ||
11 | + return false; | ||
12 | + | ||
13 | + return regexResult[1]; | ||
14 | + } catch (error) { | ||
15 | + console.log(error); | ||
16 | + return false; | ||
17 | + } | ||
18 | +} | ||
19 | + | ||
20 | +module.exports = { | ||
21 | + getCharacter: async function(req, res) { | ||
22 | + if (!req.query.nickname) { | ||
23 | + res.status(204).send(); | ||
24 | + return; | ||
25 | + } | ||
26 | + | ||
27 | + const nickname = req.query.nickname; | ||
28 | + const characterCode = await crwalCharacterCode(req.query.nickname); | ||
29 | + | ||
30 | + if (!characterCode) { | ||
31 | + res.status(404).send(); | ||
32 | + return; | ||
33 | + } | ||
34 | + | ||
35 | + console.log(characterCode); | ||
36 | + res.send({ text: characterCode }); | ||
37 | + } | ||
38 | +}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/node/routes/home.js
deleted
100644 → 0
-
Please register or login to post a comment