feat: 添加可选的代理功能支持

新增功能:
- 集成 Cloudflare WARP socks5 代理服务
- 通过环境变量 USE_PROXY 控制代理开关
- 支持自定义 HTTP/HTTPS/SOCKS5 代理服务器
- 使用 docker compose profile 管理 proxy 服务

配置方式:
- USE_PROXY=true 启用代理
- ALL_PROXY/HTTP_PROXY/HTTPS_PROXY 自定义代理
- docker compose --profile proxy up 启动 warp 服务

文件变更:
- docker-compose.yaml: 添加 warp-proxy 服务
- playwright-auth.ts: 添加代理配置逻辑
- example.env: 添加代理环境变量
- PROXY.md: 使用文档
This commit is contained in:
JamesFlare1212
2026-04-06 16:37:54 -04:00
parent 4e04063469
commit 4a97057825
4 changed files with 209 additions and 5 deletions

View File

@@ -8,16 +8,31 @@ const COOKIE_FILE_PATH = resolve(import.meta.dir, 'cookies.json');
let _inMemoryCookies: Cookie[] | null = null;
// Proxy configuration
const USE_PROXY = process.env.USE_PROXY === 'true';
const PROXY_SERVER = process.env.ALL_PROXY || process.env.HTTP_PROXY || `socks5://warp-proxy:9091`;
/**
* Login using Playwright and extract cookies
*/
export async function loginWithPlaywright(username: string, password: string): Promise<Cookie[]> {
logger.info('Starting Playwright login process...');
const browser = await chromium.launch({
const browserLaunchOptions: any = {
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
};
// Configure proxy if enabled
if (USE_PROXY) {
logger.info(`Using proxy: ${PROXY_SERVER}`);
browserLaunchOptions.proxy = {
server: PROXY_SERVER,
bypass: 'localhost,127.0.0.1,::1'
};
}
const browser = await chromium.launch(browserLaunchOptions);
try {
const context = await browser.newContext({