extract sanitizeFilename
This commit is contained in:
parent
2ae513f6c0
commit
f888981415
2 changed files with 4 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { chromium } from 'playwright'; // stealth plugin needs no outdated playwright-extra
|
import { chromium } from 'playwright'; // stealth plugin needs no outdated playwright-extra
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { dirs, jsonDb, datetime, stealth } from './util.js';
|
import { dirs, jsonDb, datetime, sanitizeFilename, stealth } from './util.js';
|
||||||
|
|
||||||
const debug = process.env.PWDEBUG == '1'; // runs headful and opens https://playwright.dev/docs/inspector
|
const debug = process.env.PWDEBUG == '1'; // runs headful and opens https://playwright.dev/docs/inspector
|
||||||
const show = process.argv.includes('show', 2);
|
const show = process.argv.includes('show', 2);
|
||||||
|
|
@ -80,7 +80,7 @@ try {
|
||||||
run.c_internal++;
|
run.c_internal++;
|
||||||
// const img = await (await card.$('img.tw-image')).getAttribute('src');
|
// const img = await (await card.$('img.tw-image')).getAttribute('src');
|
||||||
// console.log('Image:', img);
|
// console.log('Image:', img);
|
||||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'internal', `${title.replace(/[^a-z0-9]/gi, '_')}.png`);
|
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'internal', `${sanitizeFilename(title)}.png`);
|
||||||
await card.screenshot({ path: p });
|
await card.screenshot({ path: p });
|
||||||
// await page.pause();
|
// await page.pause();
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +123,7 @@ try {
|
||||||
}
|
}
|
||||||
db.data.claimed.push({title, time: datetime(), store, code});
|
db.data.claimed.push({title, time: datetime(), store, code});
|
||||||
// save screenshot of potential code just in case
|
// save screenshot of potential code just in case
|
||||||
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'external', `${title.replace(/[^a-z0-9]/gi, '_')}.png`);
|
const p = path.resolve(dirs.screenshots, 'prime-gaming', 'external', `${sanitizeFilename(title)}.png`);
|
||||||
await page.screenshot({ path: p, fullPage: true });
|
await page.screenshot({ path: p, fullPage: true });
|
||||||
console.info('Saved a screenshot of page to', p);
|
console.info('Saved a screenshot of page to', p);
|
||||||
run.c_external++;
|
run.c_external++;
|
||||||
|
|
|
||||||
1
util.js
1
util.js
|
|
@ -20,6 +20,7 @@ export const jsonDb = async file => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const datetime = (d = new Date()) => d.toISOString();
|
export const datetime = (d = new Date()) => d.toISOString();
|
||||||
|
export const sanitizeFilename = s => s.replace(/[^a-z0-9_\-]/gi, '_');
|
||||||
|
|
||||||
// stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212
|
// stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212
|
||||||
const newStealthContext = async (browser, contextOptions = {}, debug = false) => {
|
const newStealthContext = async (browser, contextOptions = {}, debug = false) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue