fix eslint errors

This commit is contained in:
Ralf Vogler 2023-11-07 18:10:22 +01:00
parent 6a34cb541d
commit e4e4f2eafa
5 changed files with 14 additions and 13 deletions

View file

@ -94,7 +94,7 @@ try {
await notify('epic-games: got captcha during login. Please check.'); await notify('epic-games: got captcha during login. Please check.');
}).catch(_ => { }); }).catch(_ => { });
page.waitForSelector('h6:has-text("Incorrect response.")').then(async () => { page.waitForSelector('h6:has-text("Incorrect response.")').then(async () => {
console.error('Incorrect repsonse for captcha!') console.error('Incorrect repsonse for captcha!');
}).catch(_ => { }); }).catch(_ => { });
// handle MFA, but don't await it // handle MFA, but don't await it
page.waitForURL('**/id/login/mfa**').then(async () => { page.waitForURL('**/id/login/mfa**').then(async () => {
@ -128,7 +128,7 @@ try {
// rarely there are no free games available -> catch Timeout // rarely there are no free games available -> catch Timeout
// TODO would be better to wait for alternative like 'coming soon' instead of waiting for timeout // TODO would be better to wait for alternative like 'coming soon' instead of waiting for timeout
// see https://github.com/vogler/free-games-claimer/issues/210#issuecomment-1727420943 // see https://github.com/vogler/free-games-claimer/issues/210#issuecomment-1727420943
console.error('Seems like currently there are no free games available in your region...') console.error('Seems like currently there are no free games available in your region...');
// urls below should then be an empty list // urls below should then be an empty list
}); });
// clicking on `game_sel` sometimes led to a 404, see https://github.com/vogler/free-games-claimer/issues/25 // clicking on `game_sel` sometimes led to a 404, see https://github.com/vogler/free-games-claimer/issues/25
@ -227,8 +227,8 @@ try {
const captcha = iframe.locator('#h_captcha_challenge_checkout_free_prod iframe'); const captcha = iframe.locator('#h_captcha_challenge_checkout_free_prod iframe');
captcha.waitFor().then(async () => { // don't await, since element may not be shown captcha.waitFor().then(async () => { // don't await, since element may not be shown
// console.info(' Got hcaptcha challenge! NopeCHA extension will likely solve it.') // console.info(' Got hcaptcha challenge! NopeCHA extension will likely solve it.')
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.') 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.');
await notify('epic-games: got captcha challenge right before claim. Use VNC to solve it manually.') await notify('epic-games: got captcha challenge right before claim. Use VNC to solve it manually.');
// await page.waitForTimeout(2000); // await page.waitForTimeout(2000);
// const p = path.resolve(cfg.dir.screenshots, 'epic-games', 'captcha', `${filenamify(datetime())}.png`); // const p = path.resolve(cfg.dir.screenshots, 'epic-games', 'captcha', `${filenamify(datetime())}.png`);
// await captcha.screenshot({ path: p }); // await captcha.screenshot({ path: p });
@ -269,5 +269,5 @@ try {
} }
} }
if (cfg.debug) writeFileSync(path.resolve(cfg.dir.browser, 'cookies.json'), JSON.stringify(await context.cookies())); if (cfg.debug) writeFileSync(path.resolve(cfg.dir.browser, 'cookies.json'), JSON.stringify(await context.cookies()));
if (page.video()) console.log('Recorded video:', await page.video().path()) if (page.video()) console.log('Recorded video:', await page.video().path());
await context.close(); await context.close();

View file

@ -1,3 +1,4 @@
/* eslint-disable no-constant-condition */
import { delay, html_game_list, notify } from "./util.js"; import { delay, html_game_list, notify } from "./util.js";
const URL_CLAIM = 'https://gaming.amazon.com/home'; // dummy URL const URL_CLAIM = 'https://gaming.amazon.com/home'; // dummy URL

View file

@ -394,5 +394,5 @@ try {
notify(`prime-gaming (${user}):<br>${html_game_list(notify_games)}`); notify(`prime-gaming (${user}):<br>${html_game_list(notify_games)}`);
} }
} }
if (page.video()) console.log('Recorded video:', await page.video().path()) if (page.video()) console.log('Recorded video:', await page.video().path());
await context.close(); await context.close();

View file

@ -74,11 +74,12 @@ const timeoutPlugin = timeout => enquirer => { // cancel prompt after timeout ms
prompt.on('submit', _ => clearTimeout(t)); prompt.on('submit', _ => clearTimeout(t));
prompt.on('cancel', _ => clearTimeout(t)); prompt.on('cancel', _ => clearTimeout(t));
}); });
} };
enquirer.use(timeoutPlugin(cfg.login_timeout)); // TODO may not want to have this timeout for all prompts; better extend Prompt and add a timeout prompt option enquirer.use(timeoutPlugin(cfg.login_timeout)); // TODO may not want to have this timeout for all prompts; better extend Prompt and add a timeout prompt option
// single prompt that just returns the non-empty value instead of an object // single prompt that just returns the non-empty value instead of an object
// @ts-ignore
export const prompt = o => enquirer.prompt({name: 'name', type: 'input', message: 'Enter value', ...o}).then(r => r.name).catch(_ => {}); export const prompt = o => enquirer.prompt({name: 'name', type: 'input', message: 'Enter value', ...o}).then(r => r.name).catch(_ => {});
export const confirm = o => prompt({type: 'confirm', message: 'Continue?', ...o}) export const confirm = o => prompt({type: 'confirm', message: 'Continue?', ...o});
// notifications via apprise CLI // notifications via apprise CLI
import { exec } from 'child_process'; import { exec } from 'child_process';
@ -93,7 +94,7 @@ export const notify = (html) => new Promise((resolve, reject) => {
if (error.message.includes('command not found')) { if (error.message.includes('command not found')) {
console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications'); console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications');
} }
return resolve(); return reject(error);
} }
if (stderr) console.error(`stderr: ${stderr}`); if (stderr) console.error(`stderr: ${stderr}`);
if (stdout) console.log(`stdout: ${stdout}`); if (stdout) console.log(`stdout: ${stdout}`);

View file

@ -1,7 +1,6 @@
// check if running the latest version // check if running the latest version
import {log} from 'console'; import {log} from 'console';
import { readFileSync } from 'fs';
import { exec } from 'child_process'; import { exec } from 'child_process';
const execp = (cmd) => new Promise((resolve, reject) => { const execp = (cmd) => new Promise((resolve, reject) => {
@ -19,7 +18,7 @@ const execp = (cmd) => new Promise((resolve, reject) => {
}); });
}); });
const git_main = () => readFileSync('.git/refs/heads/main').toString().trim(); // const git_main = () => readFileSync('.git/refs/heads/main').toString().trim();
let sha, date; let sha, date;
// if (existsSync('/.dockerenv')) { // did not work // if (existsSync('/.dockerenv')) { // did not work
@ -44,7 +43,7 @@ log('Local commit:', sha, new Date(date));
log('Online commit:', gh.sha, new Date(gh.commit.committer.date)); log('Online commit:', gh.sha, new Date(gh.commit.committer.date));
if (sha == gh.sha) { if (sha == gh.sha) {
log('Running the latest version!') log('Running the latest version!');
} else { } else {
log('Not running the latest version!') log('Not running the latest version!');
} }