This commit is contained in:
Chenyme committed 2025-10-16 13:54:49 +08:00
commit 929fcf2435
6 files changed
+29 -13

No files matched your search

+9 -1
View File
@@ -25,7 +25,15 @@ class ConfigManager:
"""配置加载器"""
try:
with open(self.config_path, "r", encoding="utf-8") as f:
return toml.load(f)[section]
config = toml.load(f)[section]
# 自动将 SOCKS5 转换为 SOCKS5H
if section == "grok" and "proxy_url" in config:
proxy_url = config["proxy_url"]
if proxy_url and proxy_url.startswith("socks5://"):
config["proxy_url"] = proxy_url.replace("socks5://", "socks5h://", 1)
return config
except Exception as e:
raise Exception(f"[Setting] 配置加载失败: {e}")
+3
View File
@@ -48,6 +48,9 @@ class CacheService:
proxy_url = setting.grok_config.get("proxy_url")
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else {}
if proxy_url:
logger.debug(f"[{self.cache_type.upper()}Cache] 使用代理: {proxy_url.split('@')[-1] if '@' in proxy_url else proxy_url}")
async with AsyncSession() as session:
logger.debug(f"[{self.cache_type.upper()}Cache] 开始下载: https://assets.grok.com{file_path}")
+9 -11
View File
@@ -146,9 +146,15 @@ class GrokClient:
raise GrokApiException("认证令牌缺失", "NO_AUTH_TOKEN")
try:
# 构建请求头和代理
# 构建请求头
headers = GrokClient._build_headers(auth_token)
proxy_config = GrokClient._get_proxy()
# 获取代理配置
proxy_url = setting.grok_config.get("proxy_url", "")
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
if proxy_url:
logger.debug(f"[Client] 使用代理: {proxy_url.split('@')[-1] if '@' in proxy_url else proxy_url}")
# 构建请求参数
request_kwargs = {
@@ -157,7 +163,7 @@ class GrokClient:
"impersonate": IMPERSONATE_BROWSER,
"timeout": REQUEST_TIMEOUT,
"stream": True,
"proxies": proxy_config if proxy_config else None
"proxies": proxies
}
# 在线程池中执行同步HTTP请求,避免阻塞事件循环
@@ -200,14 +206,6 @@ class GrokClient:
return headers
@staticmethod
def _get_proxy() -> Dict[str, str]:
"""获取代理配置"""
proxy_url = setting.grok_config.get("proxy_url", "")
if proxy_url:
return {"http": proxy_url, "https": proxy_url}
return {}
@staticmethod
def _handle_error(response, auth_token: str):
"""处理错误响应"""
+3
View File
@@ -258,6 +258,9 @@ class GrokTokenManager:
# 获取代理配置
proxy_url = setting.grok_config.get("proxy_url", "")
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
if proxy_url:
logger.debug(f"[Token] 使用代理: {proxy_url.split('@')[-1] if '@' in proxy_url else proxy_url}")
# 发送异步请求
async with AsyncSession() as session:
+4
View File
@@ -61,7 +61,11 @@ class ImageUploadManager:
cf_clearance = setting.grok_config.get("cf_clearance", "")
cookie = f"{auth_token};{cf_clearance}" if cf_clearance else auth_token
proxy_url = setting.grok_config.get("proxy_url", "")
if proxy_url:
logger.debug(f"[Upload] 使用代理: {proxy_url.split('@')[-1] if '@' in proxy_url else proxy_url}")
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
# 发送异步请求
+1 -1
View File
@@ -378,7 +378,7 @@
Proxy Url
<span class="inline-flex items-center justify-center w-3.5 h-3.5 rounded-full border border-muted-foreground text-muted-foreground cursor-help" style="font-size:10px;line-height:1" title="HTTP代理服务器地址,用于访问Grok服务,可留空">?</span>
</label>
<input id="cfgProxyUrl" class="flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm" placeholder="http://127.0.0.1:7890">
<input id="cfgProxyUrl" class="flex h-9 w-full rounded-md border border-input bg-background px-3 py-2 text-sm" placeholder="socks5://username:password@127.0.0.1:7890">
</div>
<div>
<label class="text-sm font-medium flex items-center gap-1 mb-2">