import { useEffect, useState } from 'react' import toast from 'react-hot-toast' import { Switch } from '@/components/ui/switch' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' import { getProxyConfig, updateProxyConfig } from '@/services/proxy' // 全局代理配置:作用于 LLM API + 转写 API(Groq 等)+ yt-dlp 视频下载。 // 国内访问 OpenAI / Groq / YouTube 基本都要靠它。 const ProxyConfig = () => { const [enabled, setEnabled] = useState(false) const [url, setUrl] = useState('') const [effective, setEffective] = useState('') const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) useEffect(() => { ;(async () => { try { const cfg = await getProxyConfig() setEnabled(cfg.enabled) setUrl(cfg.url) setEffective(cfg.effective) } catch { /* 拦截器已 toast */ } finally { setLoading(false) } })() }, []) const handleSave = async () => { if (enabled && !url.trim()) { toast.error('请填写代理地址,或关闭代理开关') return } setSaving(true) try { const cfg = await updateProxyConfig({ enabled, url: url.trim() }) setEnabled(cfg.enabled) setUrl(cfg.url) setEffective(cfg.effective) toast.success('代理配置已保存') } catch { /* 拦截器已 toast */ } finally { setSaving(false) } } if (loading) { return
加载代理配置…
} // env 兜底:配置没开但 effective 有值,说明来自 HTTP_PROXY 环境变量 const fromEnv = !enabled && !!effective return (
全局代理

作用于 AI 模型接口、转写接口(Groq 等)、YouTube 下载。

setUrl(e.target.value)} className="text-sm" /> {fromEnv && (

当前生效(来自环境变量):{effective}

)} {enabled && effective && (

当前生效:{effective}

)}
) } export default ProxyConfig