Skip to content

Commit fe99aa4

Browse files
authored
feat: add SCREENSHOT_DIR config option (#2801)
1 parent e631d80 commit fe99aa4

File tree

6 files changed

+14
-3
lines changed

6 files changed

+14
-3
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ node_modules/
99
dotenv
1010
*.proxies
1111
success-*.png
12+
screenshots/
1213

1314
*.wav
1415
*.mp3

Diff for: docs/reference/application.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| `PROXY_PORT` | TCP Port number on which the proxy is listening for connections. Default: `80` |
2121
| `RESTART_TIME` | Restarts chrome after defined milliseconds. `0` for never, default: `0` |
2222
| `SCREENSHOT` | Capture screenshot of page if a card is found. Default: `true` |
23+
| `SCREENSHOT_DIR` | The directory for saving the screenshots. Default: `screenshots` |
2324
| `WEB_PORT` | Starts a webserver to be able to control the bot while it is running. Setting this value starts this service. |
2425

2526
???+ info

Diff for: dotenv-example

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ PUSHOVER_TOKEN=
114114
PUSHOVER_USER=
115115
RESTART_TIME=
116116
SCREENSHOT=
117+
SCREENSHOT_DIR=
117118
SHOW_ONLY_BRANDS=
118119
SHOW_ONLY_MODELS=
119120
SHOW_ONLY_SERIES=

Diff for: src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ const page = {
383383
height: 1080,
384384
inStockWaitTime: envOrNumber(process.env.IN_STOCK_WAIT_TIME),
385385
screenshot: envOrBoolean(process.env.SCREENSHOT),
386+
screenshotDir: envOrString(process.env.SCREENSHOT_DIR, 'screenshots'),
386387
timeout: envOrNumber(process.env.PAGE_TIMEOUT, 30000),
387388
width: 1920,
388389
};

Diff for: src/store/lookup.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {processBackoffDelay} from './model/helpers/backoff';
2626
import {sendNotification} from '../messaging';
2727
import {handleCaptchaAsync} from './captcha-handler';
2828
import useProxy from '@doridian/puppeteer-page-proxy';
29+
import {promises as fs} from 'fs';
30+
import path from 'path';
2931

3032
const inStock: Record<string, boolean> = {};
3133

@@ -343,7 +345,11 @@ async function lookupIem(
343345
if (config.page.screenshot) {
344346
logger.debug('ℹ saving screenshot');
345347

346-
link.screenshot = `success-${Date.now()}.png`;
348+
await fs.mkdir(config.page.screenshotDir, {recursive: true});
349+
link.screenshot = path.join(
350+
config.page.screenshotDir,
351+
`success-${Date.now()}.png`
352+
);
347353
await page.screenshot({path: link.screenshot});
348354
}
349355
}

Diff for: src/web/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {logger} from '../logger';
1313

1414
const approot = join(__dirname, '../../../');
1515
const webroot = join(approot, './web');
16+
const screenshotDir = join(approot, config.page.screenshotDir);
1617

1718
const contentTypeMap: Record<string, string> = {
1819
css: 'text/css',
@@ -141,11 +142,11 @@ function handleAPI(
141142
return;
142143
}
143144

144-
sendFile(response, `../success-${timeStamp}.png`);
145+
sendFile(response, `success-${timeStamp}.png`, screenshotDir);
145146
return;
146147
}
147148

148-
readdir(approot, (error, files) => {
149+
readdir(screenshotDir, (error, files) => {
149150
if (error) {
150151
sendError(response, error.message);
151152
return;

0 commit comments

Comments
 (0)