Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jef authored Oct 13, 2021
2 parents c5f2963 + fe99aa4 commit deb03f5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ node_modules/
dotenv
*.proxies
success-*.png
screenshots/

*.wav
*.mp3
Expand Down
1 change: 1 addition & 0 deletions docs/reference/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dotenv-example
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ PUSHOVER_TOKEN=
PUSHOVER_USER=
RESTART_TIME=
SCREENSHOT=
SCREENSHOT_DIR=
SHOW_ONLY_BRANDS=
SHOW_ONLY_MODELS=
SHOW_ONLY_SERIES=
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
8 changes: 7 additions & 1 deletion src/store/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean> = {};

Expand Down Expand Up @@ -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});
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
css: 'text/css',
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit deb03f5

Please sign in to comment.