Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

own001 #237

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/nsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const path = require("path");
const util = require("./util");
const { getPath } = require("./lib/getPath");
const kea = require("./lib/kea");
const moment = require("moment");
const budgie = require("./budgie");
const gmail = require("./lib/gmail");
const { fetchOTPFromNusuk } = require("./lib/imap");
const { nusukNationalities: nationalities } = require("./data/nationalities");
const childProcess = require("child_process");
const sharp = require("sharp");
const abortController = new AbortController();
const registerCaptchaAbortController = new AbortController();
const loginCaptchaAbortController = new AbortController();


let page;
let data;
Expand Down Expand Up @@ -324,12 +324,14 @@ async function pageContentHandler(currentConfig) {
});
}

if (process.argv.includes("--auto") || global.headless) {
if (passenger.email.includes(".companion") || passenger.isCompanion) {
if (process.argv.includes("--auto")) {
if (passenger.email?.includes(".companion") || passenger.isCompanion) {
await page.browser().close();
} else {
await loginOrRegister("0");
}
} else if (global.headless) {
await loginOrRegister("0");
}
break;
case "index":
Expand Down Expand Up @@ -376,7 +378,8 @@ async function pageContentHandler(currentConfig) {
emailCodeCounter = 0;
clearTimeout(timerHandler);
// stop captcha attempts
abortController.abort();
registerCaptchaAbortController.abort();
loginCaptchaAbortController.abort();

await page.waitForSelector(
"#otp-inputs > input.form-control.signup-otp.me-1",
Expand Down Expand Up @@ -422,7 +425,7 @@ async function pageContentHandler(currentConfig) {

await util.clickWhenReady(createAccountSelector, page);
// save the email only at this stage
kea.updatePassenger(data.system.accountId, passenger.passportNumber, {
await kea.updatePassenger(data.system.accountId, passenger.passportNumber, {
email: passenger.email,
phone: passenger.phone,
});
Expand Down Expand Up @@ -731,6 +734,11 @@ async function pageContentHandler(currentConfig) {
util.clickWhenReady("#HaveValidResidencyNo", page);
break;
case "login":
if (global.headless) {
await page.browser().close();
process.exit(0);
return;
}
clearTimeout(timerHandler);
await closeAccountCreatedSuccessModal();
await page.$eval(
Expand Down Expand Up @@ -1049,7 +1057,7 @@ async function signup_step1(selectedTraveler) {
"#g-recaptcha-response",
URLS.SIGN_UP,
"6LcNy-0jAAAAAJDOXjYW4z7yV07DWyivFD1mmjek",
abortController.signal
registerCaptchaAbortController.signal
);

if (captchaCode) {
Expand Down Expand Up @@ -1097,7 +1105,7 @@ async function loginPassenger(selectedTraveler) {
"#g-recaptcha-response",
URLS.LOGIN,
"6LcNy-0jAAAAAJDOXjYW4z7yV07DWyivFD1mmjek",
abortController.signal
loginCaptchaAbortController.signal
);
if (!loginCaptchaValue) {
util.infoMessage(page, `Manual captcha required`);
Expand Down
8 changes: 7 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ function getOptionNode(passenger, cursor) {
}

async function controller(page, structure, travellers) {
if (global.headless) {
return;
}
if (
!structure.controller ||
!structure.controller.selector ||
Expand Down Expand Up @@ -733,6 +736,9 @@ async function closeBrowser() {
await browser.close();
}
async function commander(page, structure, travellers) {
if (global.headless) {
return;
}
if (
!structure.controller ||
!structure.controller.selector ||
Expand Down Expand Up @@ -1479,7 +1485,7 @@ async function SolveIamNotARobot(responseSelector, url, siteKey, signal) {
try {
for (let i = 0; i < 10; i++) {
if (signal?.aborted) {
console.log("Captcha solving aborted.");
console.log("Solving Captcha aborted.");
throw new Error("Captcha solving was cancelled.");
}
const res = await axios.get(
Expand Down