38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import dotenv from 'dotenv';
|
|
import type { Config } from './types.js';
|
|
|
|
dotenv.config();
|
|
|
|
function env(key: string, fallback?: string): string {
|
|
const val = process.env[key];
|
|
if (val !== undefined) return val;
|
|
if (fallback !== undefined) return fallback;
|
|
throw new Error(`Missing required environment variable: ${key}`);
|
|
}
|
|
|
|
function envInt(key: string, fallback: number): number {
|
|
const val = process.env[key];
|
|
return val ? parseInt(val, 10) : fallback;
|
|
}
|
|
|
|
export function loadConfig(cliUrls?: string[]): Config {
|
|
const envUrls = process.env['TRADE_URLS']
|
|
? process.env['TRADE_URLS'].split(',').map((u) => u.trim())
|
|
: [];
|
|
|
|
const tradeUrls = cliUrls && cliUrls.length > 0 ? cliUrls : envUrls;
|
|
|
|
return {
|
|
tradeUrls,
|
|
poe2LogPath: env(
|
|
'POE2_LOG_PATH',
|
|
'C:\\Program Files (x86)\\Steam\\steamapps\\common\\Path of Exile 2\\logs\\Client.txt',
|
|
),
|
|
poe2WindowTitle: env('POE2_WINDOW_TITLE', 'Path of Exile 2'),
|
|
browserUserDataDir: env('BROWSER_USER_DATA_DIR', './browser-data'),
|
|
travelTimeoutMs: envInt('TRAVEL_TIMEOUT_MS', 15000),
|
|
stashScanTimeoutMs: envInt('STASH_SCAN_TIMEOUT_MS', 10000),
|
|
waitForMoreItemsMs: envInt('WAIT_FOR_MORE_ITEMS_MS', 20000),
|
|
betweenTradesDelayMs: envInt('BETWEEN_TRADES_DELAY_MS', 5000),
|
|
};
|
|
}
|