Clean up Sonar issues and lint warnings
Some checks failed
build-and-push / lint (push) Failing after 5s
build-and-push / sonar (push) Has been skipped
build-and-push / docker (push) Has been skipped

This commit is contained in:
nocci 2025-12-30 16:45:17 +00:00
parent b9aa6e0073
commit 7ffc454e47
6 changed files with 124 additions and 89 deletions

View file

@ -59,7 +59,7 @@ try {
await page.click('button[type="submit"]');
await page.fill('#password', password);
await page.click('button[type="submit"]');
void (async () => {
const watchCaptchaDuringLogin = async () => {
try {
await page.waitForSelector('#h_captcha_challenge_login_prod iframe', { 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.');
@ -67,8 +67,8 @@ try {
} catch {
return;
}
})();
void (async () => {
};
const watchMfa = async () => {
try {
await page.waitForURL('**/id/login/mfa**', { timeout: cfg.login_timeout });
console.log('Enter the security code to continue - This appears to be a new device, browser or location. A security code has been sent to your email address at ...');
@ -78,7 +78,9 @@ try {
} catch {
return;
}
})();
};
watchCaptchaDuringLogin();
watchMfa();
} else {
console.log('Waiting for you to login in the browser.');
await notify('unrealengine: no longer signed in and not enough options set for automatic login.');
@ -125,7 +127,7 @@ try {
}
ids.push(id);
}
if (!ids.length) {
if (ids.length === 0) {
console.log('Nothing to claim');
} else {
await page.waitForTimeout(2000);
@ -142,7 +144,7 @@ try {
await page.locator('button.checkout').click();
console.log('Click checkout');
// maybe: Accept End User License Agreement
void (async () => {
const acceptEulaIfPresent = async () => {
try {
await page.locator('[name=accept-label]').check({ timeout: 10000 });
console.log('Accept End User License Agreement');
@ -150,7 +152,8 @@ try {
} catch {
return;
}
})();
};
acceptEulaIfPresent();
await page.waitForSelector('#webPurchaseContainer iframe');
const iframe = page.frameLocator('#webPurchaseContainer iframe');
@ -166,25 +169,27 @@ try {
// I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872
const btnAgree = iframe.locator('button:has-text("I Agree")');
void (async () => {
const acceptIfRequired = async () => {
try {
await btnAgree.waitFor({ timeout: 10000 });
await btnAgree.click();
} catch {
return;
}
})(); // EU: wait for and click 'I Agree'
}; // EU: wait for and click 'I Agree'
acceptIfRequired();
try {
// context.setDefaultTimeout(100 * 1000); // give time to solve captcha, iframe goes blank after 60s?
const captcha = iframe.locator('#h_captcha_challenge_checkout_free_prod iframe');
void (async () => {
const watchCaptchaChallenge = async () => {
try {
await captcha.waitFor({ timeout: 10000 });
console.error(' Got hcaptcha challenge! Lost trust due to too many login attempts? You can solve the captcha in the browser or get a new IP address.');
} catch {
return;
}
})(); // may time out if not shown
}; // may time out if not shown
watchCaptchaChallenge();
await page.waitForSelector('text=Thank you');
for (const id of ids) {
db.data[user][id].status = 'claimed';