mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
feat: 为 Provider 认证添加代理配置支持
- 前端新增可折叠的代理配置字段组(URL/用户名/密码) - 更新 anyrouter/cubence/new-api/yescode 模板支持代理 - 后端 provider_ops 服务验证和数据获取时支持代理 - 移除 Dockerfile 中的 ca-certificates(回退之前改动)
This commit is contained in:
@@ -180,7 +180,9 @@ def _parse_session_user_id(cookie_input: str) -> Tuple[Optional[str], Optional[s
|
||||
return None, None
|
||||
|
||||
|
||||
async def _get_acw_cookie(base_url: str, timeout: float = 10) -> Optional[str]:
|
||||
async def _get_acw_cookie(
|
||||
base_url: str, timeout: float = 10, proxy: Optional[str] = None
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
获取 acw_sc__v2 Cookie
|
||||
|
||||
@@ -189,12 +191,22 @@ async def _get_acw_cookie(base_url: str, timeout: float = 10) -> Optional[str]:
|
||||
Args:
|
||||
base_url: 目标站点 URL
|
||||
timeout: 请求超时时间
|
||||
proxy: 代理地址
|
||||
|
||||
Returns:
|
||||
Cookie 字符串 (acw_sc__v2=xxx),如果不需要或获取失败则返回 None
|
||||
"""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=timeout, verify=get_ssl_context()) as client:
|
||||
# 构建 client 参数
|
||||
client_kwargs: Dict[str, Any] = {
|
||||
"timeout": timeout,
|
||||
"verify": get_ssl_context(),
|
||||
}
|
||||
if proxy:
|
||||
client_kwargs["proxy"] = proxy
|
||||
logger.debug(f"获取 acw_sc__v2 Cookie 使用代理: {proxy}")
|
||||
|
||||
async with httpx.AsyncClient(**client_kwargs) as client:
|
||||
resp = await client.get(
|
||||
base_url,
|
||||
headers={
|
||||
@@ -253,8 +265,8 @@ class AnyrouterConnector(ProviderConnector):
|
||||
# 解析 user_id
|
||||
self._user_id, _ = _parse_session_user_id(session_cookie)
|
||||
|
||||
# 尝试获取反爬 Cookie
|
||||
self._acw_cookie = await _get_acw_cookie(self.base_url)
|
||||
# 尝试获取反爬 Cookie(使用配置中的代理)
|
||||
self._acw_cookie = await _get_acw_cookie(self.base_url, proxy=self._proxy)
|
||||
|
||||
self._set_connected()
|
||||
return True
|
||||
@@ -371,7 +383,9 @@ class AnyrouterArchitecture(ProviderArchitecture):
|
||||
Returns:
|
||||
包含 acw_cookie 的配置
|
||||
"""
|
||||
acw_cookie = await _get_acw_cookie(base_url)
|
||||
# 从 config 获取代理配置
|
||||
proxy = config.get("proxy")
|
||||
acw_cookie = await _get_acw_cookie(base_url, proxy=proxy)
|
||||
if acw_cookie:
|
||||
return {"acw_cookie": acw_cookie}
|
||||
return {}
|
||||
|
||||
@@ -193,13 +193,21 @@ class YesCodeArchitecture(ProviderArchitecture):
|
||||
|
||||
cookie_header = _build_cookie_header(cookie_input)
|
||||
|
||||
# 获取代理配置
|
||||
proxy = config.get("proxy")
|
||||
|
||||
try:
|
||||
# 构建 client 参数
|
||||
client_kwargs: Dict[str, Any] = {
|
||||
"headers": {"Cookie": cookie_header},
|
||||
"timeout": 10.0,
|
||||
"verify": get_ssl_context(),
|
||||
}
|
||||
if proxy:
|
||||
client_kwargs["proxy"] = proxy
|
||||
|
||||
# 创建临时 client 获取合并数据
|
||||
async with httpx.AsyncClient(
|
||||
headers={"Cookie": cookie_header},
|
||||
timeout=10.0,
|
||||
verify=get_ssl_context(),
|
||||
) as client:
|
||||
async with httpx.AsyncClient(**client_kwargs) as client:
|
||||
combined_data = await fetch_yescode_combined_data(client, base_url)
|
||||
extra_config["_combined_data"] = combined_data
|
||||
except Exception:
|
||||
|
||||
@@ -727,8 +727,20 @@ class ProviderOpsService:
|
||||
f"endpoint={verify_endpoint}, headers={list(headers.keys())}"
|
||||
)
|
||||
|
||||
# 获取代理配置
|
||||
proxy = config.get("proxy")
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=30.0, verify=get_ssl_context()) as client:
|
||||
# 构建 httpx client 参数
|
||||
client_kwargs: Dict[str, Any] = {
|
||||
"timeout": 30.0,
|
||||
"verify": get_ssl_context(),
|
||||
}
|
||||
if proxy:
|
||||
client_kwargs["proxy"] = proxy
|
||||
logger.debug(f"使用代理: {proxy}")
|
||||
|
||||
async with httpx.AsyncClient(**client_kwargs) as client:
|
||||
response = await client.get(verify_endpoint, headers=headers)
|
||||
|
||||
logger.debug(
|
||||
|
||||
Reference in New Issue
Block a user