Skip to content

Commit

Permalink
feat: ✨ 新增 socks 环境变量配置 \n 移除单次对话次数限制
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed May 8, 2023
1 parent 319c475 commit 8ba4b1e
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 31 deletions.
7 changes: 5 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
"mode": "auto",
"program": "${workspaceFolder}",
"env": {
"Go-Proxy-BingAI-Debug": "true",
"PORT": "8888"
"PORT": "8888",
"Go_Proxy_BingAI_Debug": "true",
"Go_Proxy_BingAI_SOCKS_URL": "192.168.0.88:1070",
// "Go_Proxy_BingAI_SOCKS_USER": "xxx",
// "Go_Proxy_BingAI_SOCKS_PWD": "xxx",
}
}
]
Expand Down
85 changes: 63 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@

⭐ 无需登录即可畅聊

⭐ 无单次对话次数限制

⭐ 需要画图等高级功能时,可登录微软账号设置用户 Cookie 进行体验

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

- [go-proxy-bing](#go-proxy-bing)
- [网页展示](#网页展示)
- [侧边栏](#侧边栏)
- [演示站点](#演示站点)
- [获取Cookie](#获取Cookie)
- [部署](#部署)
- [Docker](#Docker)
- [Release](#Release)
- [Railway](#Railway)
- [Vercel](#Vercel)
- [Render](#Render)
- [TODO](#TODO)
- [网页展示](#网页展示)
- [侧边栏](#侧边栏)
- [演示站点](#演示站点)
- [获取 Cookie](#获取Cookie)
- [环境变量](#环境变量)
- [部署](#部署)
- [Docker](#Docker)
- [Release](#Release)
- [Railway](#Railway)
- [Vercel](#Vercel)
- [Render](#Render)
- [TODO](#TODO)

## 网页展示

Expand Down Expand Up @@ -59,49 +62,87 @@

- https://bing.vcanbb.top

### Railway搭建
### Railway 搭建

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

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

### Vercel搭建
### Vercel 搭建

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

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

### Render搭建
### Render 搭建

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

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

## 获取Cookie
## 获取 Cookie

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

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

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

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

## 环境变量

```bash
# 运行端口 默认 8080 可选
PORT=8080
# Socks 环境变量 示例 可选
Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
# Socks 账号、密码 可选
Go_Proxy_BingAI_SOCKS_USER=xxx
Go_Proxy_BingAI_SOCKS_PWD=xxx
```

## 部署

> 需 https 域名 (自行配置 nginx 等)
> 支持 Linux (amd64 / arm64)、Windows (amd64 / arm64)
> 国内机器部署可配置 socks 环境变量
### Docker

> 参考 [Dockerfile](./docker/Dockerfile)[docker-compose.yml](./docker/docker-compose.yml)
示例
- docker 示例

```bash
# 运行容器 监听8080 端口
docker run -d -p 8080:8080 --name go-proxy-bingai --restart=unless-stopped adams549659584/go-proxy-bingai

# 配置 socks 环境变量
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
```

- docker compose 示例

```bash
version: '3'

services:
go-proxy-bingai:
# 镜像名称
image: adams549659584/go-proxy-bingai
# 容器名称
container_name: go-proxy-bingai
# 自启动
restart: unless-stopped
ports:
- 8080:8080
# environment:
# - Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
# - Go_Proxy_BingAI_SOCKS_USER=xxx
# - Go_Proxy_BingAI_SOCKS_PWD=xxx
```

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

一键部署,点这里 => [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/uIckWS?referralCode=BBs747)

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

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

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


## TODO

- [ ] 撰写
- [x] 撰写
- [ ] Vue3 重构
- [ ] 提示词
- [ ] 保存历史消息
- [ ] 导出消息到本地(Markdown、图片、PDF)
- [ ] 简单访问权限控制
- [ ] 简单访问权限控制
32 changes: 31 additions & 1 deletion common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"os"
"strconv"
"strings"

"github.com/andybalholm/brotli"
"golang.org/x/net/proxy"
)

var (
Expand Down Expand Up @@ -164,7 +166,35 @@ func NewSingleHostReverseProxy(target *url.URL) *httputil.ReverseProxy {
// }

// 代理请求 请求回来的内容 报错自动调用
return &httputil.ReverseProxy{Director: director, ModifyResponse: modifyFunc, ErrorHandler: errorHandler}
reverseProxy := &httputil.ReverseProxy{
Director: director,
ModifyResponse: modifyFunc,
ErrorHandler: errorHandler,
}

// socks
socksUrl := os.Getenv("Go_Proxy_BingAI_SOCKS_URL")
if socksUrl != "" {
socksUser := os.Getenv("Go_Proxy_BingAI_SOCKS_USER")
socksPwd := os.Getenv("Go_Proxy_BingAI_SOCKS_PWD")
var socksAuth *proxy.Auth
if socksUser != "" && socksPwd != "" {
socksAuth = &proxy.Auth{
User: socksUser,
Password: socksPwd,
}
}
s5Proxy, err := proxy.SOCKS5("tcp", socksUrl, socksAuth, proxy.Direct)
if err != nil {
panic(err)
}
tr := &http.Transport{
Dial: s5Proxy.Dial,
}
reverseProxy.Transport = tr
}

return reverseProxy
}

func replaceResBody(originalBody string, originalScheme string, originalHost string) string {
Expand Down
10 changes: 9 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ services:
restart: unless-stopped
ports:
- 8080:8080
# environment:
# - Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
# - Go_Proxy_BingAI_SOCKS_USER=xxx
# - Go_Proxy_BingAI_SOCKS_PWD=xxx

# go-proxy-bingai:
# # 镜像名称
Expand All @@ -25,7 +29,11 @@ services:
# networks:
# - MyNetwork
# ports:
# - 8888:8080
# - 8888:8080
# environment:
# - Go_Proxy_BingAI_SOCKS_URL=192.168.0.88:1070
# # - Go_Proxy_BingAI_SOCKS_USER=xxx
# # - Go_Proxy_BingAI_SOCKS_PWD=xxx

# networks:
# MyNetwork:
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module adams549659584/go-proxy-bingai

go 1.20

require github.com/andybalholm/brotli v1.0.5
require (
github.com/andybalholm/brotli v1.0.5
golang.org/x/net v0.10.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
2 changes: 1 addition & 1 deletion web/chat.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web/sw.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 引入workbox 框架
importScripts('./js/sw/workbox-sw.js');

const SW_VERSION = 'v1.4.2';
const SW_VERSION = 'v1.5.0';
const CACHE_PREFIX = 'BingAI';

workbox.setConfig({ debug: false, logLevel: 'warn' });
Expand Down Expand Up @@ -61,7 +61,7 @@ workbox.precaching.precacheAndRoute([
// html
{
url: '/web/chat.html',
revision: '2023.05.08',
revision: '2023.05.09',
},
{
url: '/web/compose.html',
Expand Down
2 changes: 1 addition & 1 deletion web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var IS_DEBUG_MODE bool
var WEB_PATH_MAP = make(map[string]bool)

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

var err error
if IS_DEBUG_MODE {
Expand Down

0 comments on commit 8ba4b1e

Please sign in to comment.