fix: enforce house worker request spacing and ignore local secrets
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -16,6 +16,10 @@ Thumbs.db
|
|||||||
!.env.example
|
!.env.example
|
||||||
!.env.test
|
!.env.test
|
||||||
|
|
||||||
|
# Home worker credentials and browser cookies
|
||||||
|
/house.env
|
||||||
|
/.house-worker-profile/
|
||||||
|
|
||||||
# Vite
|
# Vite
|
||||||
vite.config.js.timestamp-*
|
vite.config.js.timestamp-*
|
||||||
vite.config.ts.timestamp-*
|
vite.config.ts.timestamp-*
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ const config = {
|
|||||||
),
|
),
|
||||||
slowEveryHours: number(process.env.HOUSE_SLOW_EVERY_HOURS, 12),
|
slowEveryHours: number(process.env.HOUSE_SLOW_EVERY_HOURS, 12),
|
||||||
slowMaxPages: number(process.env.HOUSE_SLOW_MAX_PAGES, 80),
|
slowMaxPages: number(process.env.HOUSE_SLOW_MAX_PAGES, 80),
|
||||||
minGapMs: number(process.env.HOUSE_MIN_GAP_SECONDS, 8) * 1000,
|
minGapMs: Math.max(8, number(process.env.HOUSE_MIN_GAP_SECONDS, 8)) * 1000,
|
||||||
dailyBudget: number(process.env.HOUSE_DAILY_BUDGET, 1500),
|
dailyBudget: number(process.env.HOUSE_DAILY_BUDGET, 1500),
|
||||||
fetchMode: (process.env.HOUSE_FETCH_MODE ?? 'fetch') as 'fetch' | 'browser',
|
fetchMode: (process.env.HOUSE_FETCH_MODE ?? 'fetch') as 'fetch' | 'browser',
|
||||||
userAgent:
|
userAgent:
|
||||||
@@ -115,7 +115,7 @@ function slowBudgetLeft() {
|
|||||||
async function waitForTurn() {
|
async function waitForTurn() {
|
||||||
resetBudget();
|
resetBudget();
|
||||||
if (budgetUsed >= config.dailyBudget) throw new Error('Daily request budget used up');
|
if (budgetUsed >= config.dailyBudget) throw new Error('Daily request budget used up');
|
||||||
const gap = config.minGapMs * (0.8 + Math.random() * 0.7);
|
const gap = config.minGapMs * (1 + Math.random() * 0.5);
|
||||||
const wait = lastRequestAt + gap - Date.now();
|
const wait = lastRequestAt + gap - Date.now();
|
||||||
if (wait > 0) await sleep(wait);
|
if (wait > 0) await sleep(wait);
|
||||||
lastRequestAt = Date.now();
|
lastRequestAt = Date.now();
|
||||||
|
|||||||
Reference in New Issue
Block a user