Skip to content

Commit 8ba4b1e

Browse files
feat: ✨ 新增 socks 环境变量配置 \n 移除单次对话次数限制
1 parent 319c475 commit 8ba4b1e

File tree

9 files changed

+118
-31
lines changed

9 files changed

+118
-31
lines changed

.vscode/launch.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
"mode": "auto",
1212
"program": "${workspaceFolder}",
1313
"env": {
14-
"Go-Proxy-BingAI-Debug": "true",
15-
"PORT": "8888"
14+
"PORT": "8888",
15+
"Go_Proxy_BingAI_Debug": "true",
16+
"Go_Proxy_BingAI_SOCKS_URL": "192.168.0.88:1070",
17+
// "Go_Proxy_BingAI_SOCKS_USER": "xxx",
18+
// "Go_Proxy_BingAI_SOCKS_PWD": "xxx",
1619
}
1720
}
1821
]

README.md

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66

77
⭐ 无需登录即可畅聊
88

9+
⭐ 无单次对话次数限制
10+
911
⭐ 需要画图等高级功能时,可登录微软账号设置用户 Cookie 进行体验
1012

11-
⭐ 遇到一切问题,先点左下角 ![新主题](./docs/img/bing-clear.png) 试试,不行使用刷新大法(Shift + F5 或 Ctrl + Shift + R 或 右上角设置中的重置),最终大招就 清理浏览器缓存 及 Cookie ,比如(24小时限制、未登录提示等等)
13+
⭐ 遇到一切问题,先点左下角 ![新主题](./docs/img/bing-clear.png) 试试,不行使用刷新大法(Shift + F5 或 Ctrl + Shift + R 或 右上角设置中的重置),最终大招就 清理浏览器缓存 及 Cookie ,比如(24 小时限制、未登录提示等等)
1214

1315
- [go-proxy-bing](#go-proxy-bing)
14-
- [网页展示](#网页展示)
15-
- [侧边栏](#侧边栏)
16-
- [演示站点](#演示站点)
17-
- [获取Cookie](#获取Cookie)
18-
- [部署](#部署)
19-
- [Docker](#Docker)
20-
- [Release](#Release)
21-
- [Railway](#Railway)
22-
- [Vercel](#Vercel)
23-
- [Render](#Render)
24-
- [TODO](#TODO)
16+
- [网页展示](#网页展示)
17+
- [侧边栏](#侧边栏)
18+
- [演示站点](#演示站点)
19+
- [获取 Cookie](#获取Cookie)
20+
- [环境变量](#环境变量)
21+
- [部署](#部署)
22+
- [Docker](#Docker)
23+
- [Release](#Release)
24+
- [Railway](#Railway)
25+
- [Vercel](#Vercel)
26+
- [Render](#Render)
27+
- [TODO](#TODO)
2528

2629
## 网页展示
2730

@@ -59,49 +62,87 @@
5962

6063
- https://bing.vcanbb.top
6164

62-
### Railway搭建
65+
### Railway 搭建
6366

6467
- https://bing-railway.vcanbb.top
6568

6669
- https://go-proxy-bingai-production.up.railway.app
6770

68-
### Vercel搭建
71+
### Vercel 搭建
6972

7073
- https://bing-vercel.vcanbb.top
7174

7275
- https://go-proxy-bingai-git-master-adams549659584.vercel.app
7376

74-
### Render搭建
77+
### Render 搭建
7578

7679
- https://bing-render.vcanbb.top
7780

7881
- https://go-proxy-bingai.onrender.com
7982

80-
## 获取Cookie
83+
## 获取 Cookie
8184

8285
- 访问 https://www.bing.com/https://cn.bing.com/ ,登录
8386

8487
- F12 或 Ctrl + Shift + I 打开控制台
8588

86-
- 拿到 Cookie 后,在网站设置用户Cookie弹窗填入即可
89+
- 拿到 Cookie 后,在网站设置用户 Cookie 弹窗填入即可
8790

8891
![获取Cookie](./docs/img/bing-cookie.png)
8992

93+
## 环境变量
94+
95+
```bash
96+
# 运行端口 默认 8080 可选
97+
PORT=8080
98+
# Socks 环境变量 示例 可选
99+
Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
100+
# Socks 账号、密码 可选
101+
Go_Proxy_BingAI_SOCKS_USER=xxx
102+
Go_Proxy_BingAI_SOCKS_PWD=xxx
103+
```
104+
90105
## 部署
91106

92107
> 需 https 域名 (自行配置 nginx 等)
93108
94109
> 支持 Linux (amd64 / arm64)、Windows (amd64 / arm64)
95110
111+
> 国内机器部署可配置 socks 环境变量
112+
96113
### Docker
97114

98115
> 参考 [Dockerfile](./docker/Dockerfile)[docker-compose.yml](./docker/docker-compose.yml)
99116
100-
示例
117+
- docker 示例
101118

102119
```bash
103120
# 运行容器 监听8080 端口
104121
docker run -d -p 8080:8080 --name go-proxy-bingai --restart=unless-stopped adams549659584/go-proxy-bingai
122+
123+
# 配置 socks 环境变量
124+
docker run -e Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070 -e Go_Proxy_BingAI_SOCKS_USER=xxx -e Go_Proxy_BingAI_SOCKS_PWD=xxx -d -p 8080:8080 --name go-proxy-bingai --restart=unless-stopped adams549659584/go-proxy-bingai
125+
```
126+
127+
- docker compose 示例
128+
129+
```bash
130+
version: '3'
131+
132+
services:
133+
go-proxy-bingai:
134+
# 镜像名称
135+
image: adams549659584/go-proxy-bingai
136+
# 容器名称
137+
container_name: go-proxy-bingai
138+
# 自启动
139+
restart: unless-stopped
140+
ports:
141+
- 8080:8080
142+
# environment:
143+
# - Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
144+
# - Go_Proxy_BingAI_SOCKS_USER=xxx
145+
# - Go_Proxy_BingAI_SOCKS_PWD=xxx
105146
```
106147

107148
### Release
@@ -116,7 +157,8 @@ docker run -d -p 8080:8080 --name go-proxy-bingai --restart=unless-stopped adams
116157
PORT=8080
117158
RAILWAY_DOCKERFILE_PATH=docker/Dockerfile
118159
```
119-
一键部署,点这里 => [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/uIckWS?referralCode=BBs747)
160+
161+
一键部署,点这里 => [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/uIckWS?referralCode=BBs747)
120162

121163
![Railway 模板部署](./docs/img/railway-1.png)
122164

@@ -142,12 +184,11 @@ RAILWAY_DOCKERFILE_PATH=docker/Dockerfile
142184

143185
![Render 域名](./docs/img/render-2.png)
144186

145-
146187
## TODO
147188

148-
- [ ] 撰写
189+
- [x] 撰写
149190
- [ ] Vue3 重构
150191
- [ ] 提示词
151192
- [ ] 保存历史消息
152193
- [ ] 导出消息到本地(Markdown、图片、PDF)
153-
- [ ] 简单访问权限控制
194+
- [ ] 简单访问权限控制

common/proxy.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99
"net/http"
1010
"net/http/httputil"
1111
"net/url"
12+
"os"
1213
"strconv"
1314
"strings"
1415

1516
"github.com/andybalholm/brotli"
17+
"golang.org/x/net/proxy"
1618
)
1719

1820
var (
@@ -164,7 +166,35 @@ func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
164166
// }
165167

166168
// 代理请求 请求回来的内容 报错自动调用
167-
return &httputil.ReverseProxy{Director: director, ModifyResponse: modifyFunc, ErrorHandler: errorHandler}
169+
reverseProxy := &httputil.ReverseProxy{
170+
Director: director,
171+
ModifyResponse: modifyFunc,
172+
ErrorHandler: errorHandler,
173+
}
174+
175+
// socks
176+
socksUrl := os.Getenv("Go_Proxy_BingAI_SOCKS_URL")
177+
if socksUrl != "" {
178+
socksUser := os.Getenv("Go_Proxy_BingAI_SOCKS_USER")
179+
socksPwd := os.Getenv("Go_Proxy_BingAI_SOCKS_PWD")
180+
var socksAuth *proxy.Auth
181+
if socksUser != "" && socksPwd != "" {
182+
socksAuth = &proxy.Auth{
183+
User: socksUser,
184+
Password: socksPwd,
185+
}
186+
}
187+
s5Proxy, err := proxy.SOCKS5("tcp", socksUrl, socksAuth, proxy.Direct)
188+
if err != nil {
189+
panic(err)
190+
}
191+
tr := &http.Transport{
192+
Dial: s5Proxy.Dial,
193+
}
194+
reverseProxy.Transport = tr
195+
}
196+
197+
return reverseProxy
168198
}
169199

170200
func replaceResBody(originalBody string, originalScheme string, originalHost string) string {

docker/docker-compose.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ services:
1010
restart: unless-stopped
1111
ports:
1212
- 8080:8080
13+
# environment:
14+
# - Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
15+
# - Go_Proxy_BingAI_SOCKS_USER=xxx
16+
# - Go_Proxy_BingAI_SOCKS_PWD=xxx
1317

1418
# go-proxy-bingai:
1519
# # 镜像名称
@@ -25,7 +29,11 @@ services:
2529
# networks:
2630
# - MyNetwork
2731
# ports:
28-
# - 8888:8080
32+
# - 8888:8080
33+
# environment:
34+
# - Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
35+
# # - Go_Proxy_BingAI_SOCKS_USER=xxx
36+
# # - Go_Proxy_BingAI_SOCKS_PWD=xxx
2937

3038
# networks:
3139
# MyNetwork:

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module adams549659584/go-proxy-bingai
22

33
go 1.20
44

5-
require github.com/andybalholm/brotli v1.0.5
5+
require (
6+
github.com/andybalholm/brotli v1.0.5
7+
golang.org/x/net v0.10.0
8+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
22
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
3+
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
4+
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=

web/chat.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

web/sw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// 引入workbox 框架
22
importScripts('./js/sw/workbox-sw.js');
33

4-
const SW_VERSION = 'v1.4.2';
4+
const SW_VERSION = 'v1.5.0';
55
const CACHE_PREFIX = 'BingAI';
66

77
workbox.setConfig({ debug: false, logLevel: 'warn' });
@@ -61,7 +61,7 @@ workbox.precaching.precacheAndRoute([
6161
// html
6262
{
6363
url: '/web/chat.html',
64-
revision: '2023.05.08',
64+
revision: '2023.05.09',
6565
},
6666
{
6767
url: '/web/compose.html',

web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var IS_DEBUG_MODE bool
1616
var WEB_PATH_MAP = make(map[string]bool)
1717

1818
func init() {
19-
IS_DEBUG_MODE = os.Getenv("Go-Proxy-BingAI-Debug") != ""
19+
IS_DEBUG_MODE = os.Getenv("Go_Proxy_BingAI_Debug") != ""
2020

2121
var err error
2222
if IS_DEBUG_MODE {

0 commit comments

Comments
 (0)