박시진

[Modify]Response&/Global Object

......@@ -4,7 +4,7 @@ Info = {
id : "null",
pw : "null",
peed : "null",
subjects : []
subjects : {}
}
function setTimeoutPromise(ms) {
......@@ -63,7 +63,10 @@ async function login(id, pw) {
Info.pw = pw;
})
await page.goto("https://khcanvas.khu.ac.kr/");
return page;
page = await getPeed(page);
await getSubjects(page);
await browser.close();
return Info;
}
} catch (err) {
console.log(err);
......@@ -123,6 +126,10 @@ async function getSubjects(page) {
// promise1.then(value => {
// Info.data = value;
// })
const promise3 = Promise.resolve(data);
promise3.then(value => {
Info.subjects = value;
})
return data;
}
......@@ -152,23 +159,20 @@ async function getOne(page, index) {
//}
// if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ]
// exports.login = login;
exports.login = login;
// exports.getPeed = getPeed;
// exports.getSubjects = getSubjects;
//console test
async function runrun() {
page = await login("lorem", "lorem");
await getPeed(page);
// await getPeed(page).then((value => {
// console.log(value.link);
// }));
// await getSubjects(page);
console.log(Info);
// async function runrun() {
// page = await login("lorem", "lorem");
// await getPeed(page);
// await getSubjects(page);
// console.log(Info);
}
runrun();
// }
// runrun();
......
......@@ -5,16 +5,16 @@ const { getPeed, getSubjects, login } = require("../libs/E_Campus.js");
router.post("/", async (req, res) => {
console.log(`listened /login ${req.body.id} ${req.body.pw}`);
const page = await login(req.body.id, req.body.pw);
if (page) {
const Info = await login(req.body.id, req.body.pw);
if (Info.id != "null") {
try {
const peed = await getPeed(page);
res.send(peed);
// const peed = await getPeed(page);
res.send("success");
} catch (e) {
console.log(e);
res.send("error");
}
} else res.send("login failed");
} else res.send("failed");
});
module.exports = router;
......