feat: Add Rod-based browser automation for OAuth authorization.
This commit is contained in:
@@ -2,6 +2,7 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -18,6 +19,34 @@ type RodAuth struct {
|
|||||||
proxy string
|
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 授权器
|
// NewRodAuth 创建 Rod 授权器
|
||||||
func NewRodAuth(headless bool, proxy string) (*RodAuth, error) {
|
func NewRodAuth(headless bool, proxy string) (*RodAuth, error) {
|
||||||
l := launcher.New().
|
l := launcher.New().
|
||||||
@@ -33,6 +62,11 @@ func NewRodAuth(headless bool, proxy string) (*RodAuth, error) {
|
|||||||
Set("metrics-recording-only").
|
Set("metrics-recording-only").
|
||||||
Set("no-first-run")
|
Set("no-first-run")
|
||||||
|
|
||||||
|
// 使用系统 Chromium(如果存在)
|
||||||
|
if chromiumPath := getChromiumPath(); chromiumPath != "" {
|
||||||
|
l = l.Bin(chromiumPath)
|
||||||
|
}
|
||||||
|
|
||||||
if proxy != "" {
|
if proxy != "" {
|
||||||
l = l.Proxy(proxy)
|
l = l.Proxy(proxy)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user