From a1403c7605d413e58cb9932fbb7021faf3f87c37 Mon Sep 17 00:00:00 2001 From: lyy0709 <2722707908@qq.com> Date: Fri, 19 Apr 2024 21:43:14 +0800 Subject: [PATCH 1/2] Fixed some minor issues --- Dockerfile | 5 ++++- backend-anon/backend-anon.go | 2 +- backend-api/backend-api.go | 2 +- config.yaml | 1 + config/config.go | 30 ++++++++++++++++++++++++++++-- docker-compose.yml | 3 +-- resource/template/setup.html | 7 +++++++ 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 50905ef..69208dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,9 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . # 使用 scratch 作为基础镜像 FROM scratch +# 设置工作目录 +WORKDIR /app + # 从 builder 镜像中复制 /etc/ssl/certs 到当前镜像中,这样你的应用就可以访问带有 SSL 证书的站点了 COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ @@ -31,7 +34,7 @@ COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo # 从 builder 镜像中复制应用到当前镜像中 COPY --from=builder /app/main /app/main -# 从 builder 镜像中复制应用到当前镜像中 +# 从 builder 镜像中复制目录到当前镜像中 COPY --from=builder /app/resource /app/resource # 指定环境变量 TZ,你可以在运行 Docker 容器时通过 -e 参数来覆盖这个值 diff --git a/backend-anon/backend-anon.go b/backend-anon/backend-anon.go index 1970812..9db2950 100644 --- a/backend-anon/backend-anon.go +++ b/backend-anon/backend-anon.go @@ -33,7 +33,7 @@ func PromptLibrary(r *ghttp.Request) { "Origin": "https://chat.openai.com", "Referer": "https://chat.openai.com/", "Host": "chat.openai.com", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", "OAI-Language": r.Header.Get("OAI-Language"), "OAI-Device-Id": r.Header.Get("OAI-Device-Id"), }) diff --git a/backend-api/backend-api.go b/backend-api/backend-api.go index 7b03ef6..714e31c 100644 --- a/backend-api/backend-api.go +++ b/backend-api/backend-api.go @@ -34,7 +34,7 @@ func PromptLibrary(r *ghttp.Request) { "Origin": "https://chat.openai.com", "Referer": "https://chat.openai.com/", "Host": "chat.openai.com", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", "OAI-Language": r.Header.Get("OAI-Language"), } accessToken := config.GetAccessToken(ctx) diff --git a/config.yaml b/config.yaml index 523c42d..b5d1c0e 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,6 @@ PORT: 9315 JA3_PROXY: "http://cockroachai:cockroachai@172.17.0.1:9988" +# ASSET_PREFIX: "" # 用于配置静态资源 ADMIN_PASSWORD: "xyhelper" USERTOKENS: - "hello" diff --git a/config/config.go b/config/config.go index 895d663..67a9d1e 100644 --- a/config/config.go +++ b/config/config.go @@ -2,7 +2,8 @@ package config import ( "net/url" - + "time" + "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" @@ -92,11 +93,27 @@ func init() { BuildId = buildId } g.Log().Info(ctx, "BuildId:", BuildId) + // 每小时更新一次 + go func() { + for { + time.Sleep(time.Hour) + build := CheckNewVersion(ctx) + if build != "" { + BuildId = build + } + g.Log().Info(ctx, "BuildId:", BuildId) + cacheBuildId := CheckVersion(ctx, AssetPrefix) + if cacheBuildId != "" { + CacheBuildId = cacheBuildId + } + g.Log().Info(ctx, "CacheBuildId:", CacheBuildId) + } + }() ProxyClient = g.Client().Proxy(Ja3Proxy.String()).SetBrowserMode(true).SetHeaderMap(g.MapStrStr{ "Origin": "https://chat.openai.com", "Referer": "https://chat.openai.com/", "Host": "chat.openai.com", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", }) // 加载session @@ -158,6 +175,15 @@ func CheckVersion(ctx g.Ctx, assetPrefix string) (CacheBuildId string) { return } +// 检查是否有新版本 +func CheckNewVersion(ctx g.Ctx) (buildId string) { + resVar := g.Client().GetVar(ctx, CHATPROXY(ctx)+"/ping") + resJson := gjson.New(resVar) + + buildId = resJson.Get("buildId").String() + return +} + func GetEnvScript(ctx g.Ctx) string { script, err := gview.ParseContent(ctx, envScriptTpl, g.Map{ "ArkoseUrl": ArkoseUrl, diff --git a/docker-compose.yml b/docker-compose.yml index ed5f033..4b517d4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,5 +5,4 @@ services: ports: - "9000:9315" #左侧为暴露的端口 volumes: - - ./config.yaml:/config.yaml - - ./resource:/app/resource \ No newline at end of file + - ./config:/app/config \ No newline at end of file diff --git a/resource/template/setup.html b/resource/template/setup.html index 8ee58e0..88cd6f6 100644 --- a/resource/template/setup.html +++ b/resource/template/setup.html @@ -106,6 +106,13 @@

蟑螂账号管理

document.addEventListener('DOMContentLoaded', function () { var eyeIcon = document.getElementById('eyeIcon'); eyeIcon.addEventListener('click', togglePasswordVisibility); + var result = document.getElementById('result'); + if (result.textContent.startsWith('{"accessToken":')) { + result.style.backgroundColor = 'green'; + result.textContent = "获取成功"; + } else { + result.style.backgroundColor = 'red'; + } }); From 2471b262bcf48a0f8c7f65740cf272cdb6af7a2a Mon Sep 17 00:00:00 2001 From: lyy0709 <2722707908@qq.com> Date: Fri, 19 Apr 2024 21:49:00 +0800 Subject: [PATCH 2/2] Fixed some minor issues --- config/config.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/config/config.go b/config/config.go index 67a9d1e..b704f9e 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,7 @@ package config import ( "net/url" "time" - + "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/frame/g" @@ -97,7 +97,7 @@ func init() { go func() { for { time.Sleep(time.Hour) - build := CheckNewVersion(ctx) + build := GetBuildId(ctx) if build != "" { BuildId = build } @@ -175,15 +175,6 @@ func CheckVersion(ctx g.Ctx, assetPrefix string) (CacheBuildId string) { return } -// 检查是否有新版本 -func CheckNewVersion(ctx g.Ctx) (buildId string) { - resVar := g.Client().GetVar(ctx, CHATPROXY(ctx)+"/ping") - resJson := gjson.New(resVar) - - buildId = resJson.Get("buildId").String() - return -} - func GetEnvScript(ctx g.Ctx) string { script, err := gview.ParseContent(ctx, envScriptTpl, g.Map{ "ArkoseUrl": ArkoseUrl,