feat: Add Rod-based browser automation for OAuth authorization.

This commit is contained in:
2026-01-30 19:42:55 +08:00
parent 65341fa300
commit 119b24efb2

View File

@@ -2,6 +2,7 @@ package auth
import (
"fmt"
"os"
"strings"
"time"
@@ -18,6 +19,34 @@ type RodAuth struct {
proxy string
}
// getChromiumPath 获取 Chromium 路径
func getChromiumPath() string {
// 优先使用环境变量
if path := os.Getenv("CHROME_BIN"); path != "" {
if _, err := os.Stat(path); err == nil {
return path
}
}
if path := os.Getenv("CHROME_PATH"); path != "" {
if _, err := os.Stat(path); err == nil {
return path
}
}
// Alpine Linux 默认路径
paths := []string{
"/usr/bin/chromium-browser",
"/usr/bin/chromium",
"/usr/bin/google-chrome",
"/usr/bin/google-chrome-stable",
}
for _, path := range paths {
if _, err := os.Stat(path); err == nil {
return path
}
}
return "" // 让 Rod 自动下载
}
// NewRodAuth 创建 Rod 授权器
func NewRodAuth(headless bool, proxy string) (*RodAuth, error) {
l := launcher.New().
@@ -33,6 +62,11 @@ func NewRodAuth(headless bool, proxy string) (*RodAuth, error) {
Set("metrics-recording-only").
Set("no-first-run")
// 使用系统 Chromium如果存在
if chromiumPath := getChromiumPath(); chromiumPath != "" {
l = l.Bin(chromiumPath)
}
if proxy != "" {
l = l.Proxy(proxy)
}