From c08b40363362ee2d9329ab2073426953a2969c25 Mon Sep 17 00:00:00 2001 From: AymanA Date: Sat, 21 Dec 2024 17:47:35 +0200 Subject: [PATCH] own001 --- src/nsh.js | 26 +++++++++++++++++--------- src/util.js | 8 +++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/nsh.js b/src/nsh.js index c8bfded..3ad6dfb 100644 --- a/src/nsh.js +++ b/src/nsh.js @@ -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; @@ -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": @@ -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", @@ -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, }); @@ -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( @@ -1049,7 +1057,7 @@ async function signup_step1(selectedTraveler) { "#g-recaptcha-response", URLS.SIGN_UP, "6LcNy-0jAAAAAJDOXjYW4z7yV07DWyivFD1mmjek", - abortController.signal + registerCaptchaAbortController.signal ); if (captchaCode) { @@ -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`); diff --git a/src/util.js b/src/util.js index 39c3c7f..483b14a 100644 --- a/src/util.js +++ b/src/util.js @@ -592,6 +592,9 @@ function getOptionNode(passenger, cursor) { } async function controller(page, structure, travellers) { + if (global.headless) { + return; + } if ( !structure.controller || !structure.controller.selector || @@ -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 || @@ -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(