Clean Sonar issues in store scripts
This commit is contained in:
parent
397871b012
commit
5f919039ab
6 changed files with 172 additions and 187 deletions
39
gog.js
39
gog.js
|
|
@ -31,7 +31,7 @@ handleSIGINT(context);
|
|||
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
|
||||
|
||||
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
|
||||
await page.setViewportSize({ width: cfg.width, height: cfg.height }); // TODO workaround for https://github.com/vogler/free-games-claimer/issues/277 until Playwright fixes it
|
||||
await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaround for https://github.com/vogler/free-games-claimer/issues/277 until Playwright fixes it
|
||||
|
||||
const notify_games = [];
|
||||
let user;
|
||||
|
|
@ -47,7 +47,7 @@ try {
|
|||
console.error('Not signed in anymore.');
|
||||
await signIn.click();
|
||||
// it then creates an iframe for the login
|
||||
await page.waitForSelector('#GalaxyAccountsFrameContainer iframe'); // TODO needed?
|
||||
await page.waitForSelector('#GalaxyAccountsFrameContainer iframe');
|
||||
const iframe = page.frameLocator('#GalaxyAccountsFrameContainer iframe');
|
||||
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in
|
||||
console.info(`Login timeout is ${cfg.login_timeout / 1000} seconds!`);
|
||||
|
|
@ -60,19 +60,24 @@ try {
|
|||
await iframe.locator('#login_username').fill(email);
|
||||
await iframe.locator('#login_password').fill(password);
|
||||
await iframe.locator('#login_login').click();
|
||||
// handle MFA, but don't await it
|
||||
iframe.locator('form[name=second_step_authentication]').waitFor().then(async () => {
|
||||
console.log('Two-Step Verification - Enter security code');
|
||||
console.log(await iframe.locator('.form__description').innerText());
|
||||
const otp = await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 4 || 'The code must be 4 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
|
||||
await iframe.locator('#second_step_authentication_token_letter_1').pressSequentially(otp.toString(), { delay: 10 });
|
||||
await iframe.locator('#second_step_authentication_send').click();
|
||||
await page.waitForTimeout(1000); // TODO still needed with wait for username below?
|
||||
}).catch(_ => { });
|
||||
iframe.locator('text=Invalid captcha').waitFor().then(() => {
|
||||
console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.');
|
||||
notify('gog: got captcha during login. Please check.');
|
||||
}).catch(_ => { });
|
||||
void (async () => {
|
||||
try {
|
||||
await iframe.locator('form[name=second_step_authentication]').waitFor({ timeout: 15000 });
|
||||
console.log('Two-Step Verification - Enter security code');
|
||||
console.log(await iframe.locator('.form__description').innerText());
|
||||
const otp = await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 4 || 'The code must be 4 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
|
||||
await iframe.locator('#second_step_authentication_token_letter_1').pressSequentially(otp.toString(), { delay: 10 });
|
||||
await iframe.locator('#second_step_authentication_send').click();
|
||||
await page.waitForTimeout(1000);
|
||||
} catch {}
|
||||
})();
|
||||
void (async () => {
|
||||
try {
|
||||
await iframe.locator('text=Invalid captcha').waitFor({ timeout: 15000 });
|
||||
console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.');
|
||||
notify('gog: got captcha during login. Please check.');
|
||||
} catch {}
|
||||
})();
|
||||
await page.waitForSelector('#menuUsername');
|
||||
} else {
|
||||
console.log('Waiting for you to login in the browser.');
|
||||
|
|
@ -101,11 +106,9 @@ try {
|
|||
console.log(`Current free game: ${chalk.blue(title)} - ${url}`);
|
||||
db.data[user][title] ||= { title, time: datetime(), url };
|
||||
if (cfg.dryrun) process.exit(1);
|
||||
// await page.locator('#giveaway:not(.is-loading)').waitFor(); // otherwise screenshot is sometimes with loading indicator instead of game title; #TODO fix, skipped due to timeout, see #240
|
||||
await banner.screenshot({ path: screenshot(`${filenamify(title)}.png`) }); // overwrites every time - only keep first?
|
||||
|
||||
// await banner.getByRole('button', { name: 'Add to library' }).click();
|
||||
// instead of clicking the button, we visit the auto-claim URL which gives as a JSON response which is easier than checking the state of a button
|
||||
// instead of clicking the button, visit the auto-claim URL which gives a JSON response
|
||||
await page.goto('https://www.gog.com/giveaway/claim');
|
||||
const response = await page.innerText('body');
|
||||
// console.log(response);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue