Skip to content

Commit

Permalink
Merge pull request #2 from lyy0709/master
Browse files Browse the repository at this point in the history
  • Loading branch information
gcslaoli authored Apr 27, 2024
2 parents 98948ce + 3878f5a commit c30ed54
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand All @@ -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 参数来覆盖这个值
Expand Down
2 changes: 1 addition & 1 deletion backend-anon/backend-anon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
})
Expand Down
2 changes: 1 addition & 1 deletion backend-api/backend-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PORT: 9315
JA3_PROXY: "http://cockroachai:[email protected]:9988"
# ASSET_PREFIX: "" # 用于配置静态资源
ADMIN_PASSWORD: "xyhelper"
USERTOKENS:
- "hello"
Expand Down
19 changes: 18 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"net/url"
"time"

"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
Expand Down Expand Up @@ -92,11 +93,27 @@ func init() {
BuildId = buildId
}
g.Log().Info(ctx, "BuildId:", BuildId)
// 每小时更新一次
go func() {
for {
time.Sleep(time.Hour)
build := GetBuildId(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
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ services:
ports:
- "9000:9315" #左侧为暴露的端口
volumes:
- ./config.yaml:/config.yaml
- ./resource:/app/resource
- ./config:/app/config
7 changes: 7 additions & 0 deletions resource/template/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ <h2>蟑螂账号管理</h2>
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';
}
});
</script>
</body>
Expand Down

0 comments on commit c30ed54

Please sign in to comment.