diff --git a/.gitignore b/.gitignore index 3829afeae4..5adeacf962 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ node_modules/ dotenv *.proxies success-*.png +screenshots/ *.wav *.mp3 diff --git a/docs/reference/application.md b/docs/reference/application.md index 99b2f31559..39656e5366 100644 --- a/docs/reference/application.md +++ b/docs/reference/application.md @@ -20,6 +20,7 @@ | `PROXY_PORT` | TCP Port number on which the proxy is listening for connections. Default: `80` | | `RESTART_TIME` | Restarts chrome after defined milliseconds. `0` for never, default: `0` | | `SCREENSHOT` | Capture screenshot of page if a card is found. Default: `true` | +| `SCREENSHOT_DIR` | The directory for saving the screenshots. Default: `screenshots` | | `WEB_PORT` | Starts a webserver to be able to control the bot while it is running. Setting this value starts this service. | ???+ info diff --git a/dotenv-example b/dotenv-example index 417282b825..2342742e29 100644 --- a/dotenv-example +++ b/dotenv-example @@ -114,6 +114,7 @@ PUSHOVER_TOKEN= PUSHOVER_USER= RESTART_TIME= SCREENSHOT= +SCREENSHOT_DIR= SHOW_ONLY_BRANDS= SHOW_ONLY_MODELS= SHOW_ONLY_SERIES= diff --git a/src/config.ts b/src/config.ts index a004d3e43a..ec6f871fd5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -383,6 +383,7 @@ const page = { height: 1080, inStockWaitTime: envOrNumber(process.env.IN_STOCK_WAIT_TIME), screenshot: envOrBoolean(process.env.SCREENSHOT), + screenshotDir: envOrString(process.env.SCREENSHOT_DIR, 'screenshots'), timeout: envOrNumber(process.env.PAGE_TIMEOUT, 30000), width: 1920, }; diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 997a931e42..1c40cc613e 100644 --- a/src/store/lookup.ts +++ b/src/store/lookup.ts @@ -26,6 +26,8 @@ import {processBackoffDelay} from './model/helpers/backoff'; import {sendNotification} from '../messaging'; import {handleCaptchaAsync} from './captcha-handler'; import useProxy from '@doridian/puppeteer-page-proxy'; +import {promises as fs} from 'fs'; +import path from 'path'; const inStock: Record = {}; @@ -343,7 +345,11 @@ async function lookupIem( if (config.page.screenshot) { logger.debug('ℹ saving screenshot'); - link.screenshot = `success-${Date.now()}.png`; + await fs.mkdir(config.page.screenshotDir, {recursive: true}); + link.screenshot = path.join( + config.page.screenshotDir, + `success-${Date.now()}.png` + ); await page.screenshot({path: link.screenshot}); } } diff --git a/src/web/index.ts b/src/web/index.ts index af07f91db1..96b40c9454 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -13,6 +13,7 @@ import {logger} from '../logger'; const approot = join(__dirname, '../../../'); const webroot = join(approot, './web'); +const screenshotDir = join(approot, config.page.screenshotDir); const contentTypeMap: Record = { css: 'text/css', @@ -141,11 +142,11 @@ function handleAPI( return; } - sendFile(response, `../success-${timeStamp}.png`); + sendFile(response, `success-${timeStamp}.png`, screenshotDir); return; } - readdir(approot, (error, files) => { + readdir(screenshotDir, (error, files) => { if (error) { sendError(response, error.message); return;