박시진

[Modify]Response&/Global Object

...@@ -4,7 +4,7 @@ Info = { ...@@ -4,7 +4,7 @@ Info = {
4 id : "null", 4 id : "null",
5 pw : "null", 5 pw : "null",
6 peed : "null", 6 peed : "null",
7 - subjects : [] 7 + subjects : {}
8 } 8 }
9 9
10 function setTimeoutPromise(ms) { 10 function setTimeoutPromise(ms) {
...@@ -63,7 +63,10 @@ async function login(id, pw) { ...@@ -63,7 +63,10 @@ async function login(id, pw) {
63 Info.pw = pw; 63 Info.pw = pw;
64 }) 64 })
65 await page.goto("https://khcanvas.khu.ac.kr/"); 65 await page.goto("https://khcanvas.khu.ac.kr/");
66 - return page; 66 + page = await getPeed(page);
67 + await getSubjects(page);
68 + await browser.close();
69 + return Info;
67 } 70 }
68 } catch (err) { 71 } catch (err) {
69 console.log(err); 72 console.log(err);
...@@ -123,6 +126,10 @@ async function getSubjects(page) { ...@@ -123,6 +126,10 @@ async function getSubjects(page) {
123 // promise1.then(value => { 126 // promise1.then(value => {
124 // Info.data = value; 127 // Info.data = value;
125 // }) 128 // })
129 + const promise3 = Promise.resolve(data);
130 + promise3.then(value => {
131 + Info.subjects = value;
132 + })
126 return data; 133 return data;
127 } 134 }
128 135
...@@ -152,23 +159,20 @@ async function getOne(page, index) { ...@@ -152,23 +159,20 @@ async function getOne(page, index) {
152 //} 159 //}
153 // if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ] 160 // if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ]
154 161
155 -// exports.login = login; 162 +exports.login = login;
156 // exports.getPeed = getPeed; 163 // exports.getPeed = getPeed;
157 // exports.getSubjects = getSubjects; 164 // exports.getSubjects = getSubjects;
158 165
159 166
160 167
161 //console test 168 //console test
162 -async function runrun() { 169 +// async function runrun() {
163 - page = await login("lorem", "lorem"); 170 +// page = await login("lorem", "lorem");
164 - await getPeed(page); 171 +// await getPeed(page);
165 - // await getPeed(page).then((value => { 172 +// await getSubjects(page);
166 - // console.log(value.link); 173 +// console.log(Info);
167 - // }));
168 - // await getSubjects(page);
169 - console.log(Info);
170 174
171 -} 175 +// }
172 -runrun(); 176 +// runrun();
173 177
174 178
......
...@@ -5,16 +5,16 @@ const { getPeed, getSubjects, login } = require("../libs/E_Campus.js"); ...@@ -5,16 +5,16 @@ const { getPeed, getSubjects, login } = require("../libs/E_Campus.js");
5 5
6 router.post("/", async (req, res) => { 6 router.post("/", async (req, res) => {
7 console.log(`listened /login ${req.body.id} ${req.body.pw}`); 7 console.log(`listened /login ${req.body.id} ${req.body.pw}`);
8 - const page = await login(req.body.id, req.body.pw); 8 + const Info = await login(req.body.id, req.body.pw);
9 - if (page) { 9 + if (Info.id != "null") {
10 try { 10 try {
11 - const peed = await getPeed(page); 11 + // const peed = await getPeed(page);
12 - res.send(peed); 12 + res.send("success");
13 } catch (e) { 13 } catch (e) {
14 console.log(e); 14 console.log(e);
15 res.send("error"); 15 res.send("error");
16 } 16 }
17 - } else res.send("login failed"); 17 + } else res.send("failed");
18 }); 18 });
19 19
20 module.exports = router; 20 module.exports = router;
......