diff --git a/README.md b/README.md index d07ced3273..e28f98be9b 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,8 @@ services: | `API_REVERSE_PROXY` | 可选,`Web API` 时可用 | `Web API` 反向代理地址 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) | | `SOCKS_PROXY_HOST` | 可选,和 `SOCKS_PROXY_PORT` 一起时生效 | Socks代理 | | `SOCKS_PROXY_PORT` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理端口 | +| `SOCKS_PROXY_USERNAME` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理用户名 | +| `SOCKS_PROXY_PASSWORD` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理密码 | | `HTTPS_PROXY` | 可选 | HTTPS 代理,支持 http,https, socks5 | | `ALL_PROXY` | 可选 | 所有代理 代理,支持 http,https, socks5 | diff --git a/service/.env.example b/service/.env.example index ac8e9d6467..280fcb613d 100644 --- a/service/.env.example +++ b/service/.env.example @@ -28,6 +28,12 @@ SOCKS_PROXY_HOST= # Socks Proxy Port SOCKS_PROXY_PORT= +# Socks Proxy Username +SOCKS_PROXY_USERNAME= + +# Socks Proxy Password +SOCKS_PROXY_PASSWORD= + # HTTPS PROXY HTTPS_PROXY= diff --git a/service/src/chatgpt/index.ts b/service/src/chatgpt/index.ts index c702e6ac81..3f95588067 100644 --- a/service/src/chatgpt/index.ts +++ b/service/src/chatgpt/index.ts @@ -158,17 +158,19 @@ async function chatConfig() { } function setupProxy(options: ChatGPTAPIOptions | ChatGPTUnofficialProxyAPIOptions) { - if (process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_PORT) { + if (isNotEmptyString(process.env.SOCKS_PROXY_HOST) && isNotEmptyString(process.env.SOCKS_PROXY_PORT)) { const agent = new SocksProxyAgent({ hostname: process.env.SOCKS_PROXY_HOST, port: process.env.SOCKS_PROXY_PORT, + userId: isNotEmptyString(process.env.SOCKS_PROXY_USERNAME) ? process.env.SOCKS_PROXY_USERNAME : undefined, + password: isNotEmptyString(process.env.SOCKS_PROXY_PASSWORD) ? process.env.SOCKS_PROXY_PASSWORD : undefined, }) options.fetch = (url, options) => { return fetch(url, { agent, ...options }) } } else { - if (process.env.HTTPS_PROXY || process.env.ALL_PROXY) { + if (isNotEmptyString(process.env.HTTPS_PROXY) || isNotEmptyString(process.env.ALL_PROXY)) { const httpsProxy = process.env.HTTPS_PROXY || process.env.ALL_PROXY if (httpsProxy) { const agent = new HttpsProxyAgent(httpsProxy)