Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhuapiaoyuan committed Feb 18, 2024
2 parents c2cf4d1 + 4d4704d commit 9e2fa94
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 132 deletions.
35 changes: 34 additions & 1 deletion backend-api/backend-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -59,6 +60,7 @@ func ProxyAll(r *ghttp.Request) {
g.Log().Debug(ctx, "userToken", userToken)

isStream := strings.Contains(r.Header.Get("accept"), "text/event-stream")

// 获得当前的请求域名
// g.Log().Debug(ctx, "ProxyAll", r.URL.Path, r.Header.Get("accept"), isStream)

Expand Down Expand Up @@ -100,7 +102,15 @@ func ProxyAll(r *ghttp.Request) {
isCreateConversation := strings.HasPrefix(path, "/backend-api/conversation/gen_title")
isShare := strings.HasPrefix(path, "/backend-api/share/creat")
isLoadModels := strings.HasPrefix(path, "/backend-api/models")
if strings.HasPrefix(path, "/backend-api/conversation") {
// log content-type
g.Log().Debug(ctx, "content-type", response.Header.Get("Content-Type"))
}

// 判断response的Cotnent-Type是否是json
if response.Header.Get("Content-Type") == "application/json" {
isStream = false
}
if isCreateConversation {
CreateConversation(ctx, userId, chatgptId, accessToken, r.UserAgent(), path)
} else if isLoadModels {
Expand All @@ -123,7 +133,30 @@ func ProxyAll(r *ghttp.Request) {
if shouldReturn {
return returnValue
}
modifiedBody := strings.Replace(string(originalBody), "https://files.oaiusercontent.com", cdnhost, -1)
bodyStr := string(originalBody)
// 判断字符串是否包含 wss://
modifiedBody := strings.Replace(bodyStr, "https://files.oaiusercontent.com", cdnhost, -1)

if strings.Contains(bodyStr, "wss://") {
// 使用正则 wss://中间的域名/client/hubs/conversations 把域名替换成本地域名

// modifiedBody = strings.Replace(string(modifiedBody), "wss://chatgpt-async-webps-prod-southcentralus-22.webpubsub.azure.com",
// "wss://host.docker.internal:7999", -1)

re := regexp.MustCompile(`wss://([^/]+)/client`)

// 在URL中搜索匹配的部分
matches := re.FindStringSubmatch(bodyStr)

if len(matches) > 1 {
modifiedBody = strings.Replace(modifiedBody, "wss://"+matches[1]+"/client/hubs/conversations?", "ws://127.0.0.1:7999/client/hubs/conversations?host="+matches[1]+"&", -1)
g.Log().Debug(ctx, "wss替换成ws", matches[1])
} else {

g.Log().Debug(ctx, "wss替换成ws失败", bodyStr)
}
}

// 将修改后的内容写回响应体
response.Body = io.NopCloser(bytes.NewBufferString(modifiedBody))
// 更新Content-Length
Expand Down
10 changes: 5 additions & 5 deletions config.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ server:
serverRoot: "resource/public"
clientMaxBodySize: 104857600 # 100MB in bytes 100*1024*1024

logger:
path: "./data/logs/"
file: "{Y-m-d}.log"
level : "info"
stdout: true
# logger:
# path: "./data/logs/"
# file: "{Y-m-d}.log"
# level : "info"
# stdout: true


database:
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var (
FreeModels = garray.NewStrArray()
PlusModels = garray.NewStrArray()
ArkoseUrl = "https://tcr9i.closeai.biz/v2/"
BuildId = "MCkVH1jJi3yNLkMToVDdU"
CacheBuildId = "MCkVH1jJi3yNLkMToVDdU"
BuildId = "LxJWDayKNMzRjO_Ay4ljN"
CacheBuildId = "LxJWDayKNMzRjO_Ay4ljN"
AssetPrefix = "https://oaistatic-cdn.closeai.biz"
PK40 = "35536E1E-65B4-4D96-9D97-6ADB7EFF8147"
PK35 = "3D86FBBA-9D22-402A-B512-3420086BA6CC"
Expand Down
57 changes: 28 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,60 @@ module chatgpt-mirror-server
go 1.18

require (
github.com/andybalholm/brotli v1.0.6
github.com/cool-team-official/cool-admin-go/contrib/drivers/mysql v1.5.2
github.com/cool-team-official/cool-admin-go/contrib/drivers/sqlite v1.5.2
github.com/cool-team-official/cool-admin-go/cool v1.5.2
github.com/cool-team-official/cool-admin-go/modules/base v1.5.2
github.com/cool-team-official/cool-admin-go/modules/dict v1.5.2
github.com/cool-team-official/cool-admin-go/modules/space v1.5.2
github.com/cool-team-official/cool-admin-go/modules/task v1.5.2
github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.6
github.com/gogf/gf/v2 v2.5.6
github.com/andybalholm/brotli v1.1.0
github.com/cool-team-official/cool-admin-go/contrib/drivers/mysql v1.5.9
github.com/cool-team-official/cool-admin-go/contrib/drivers/sqlite v1.5.9
github.com/cool-team-official/cool-admin-go/cool v1.5.9
github.com/cool-team-official/cool-admin-go/modules/base v1.5.9
github.com/cool-team-official/cool-admin-go/modules/dict v1.5.9
github.com/cool-team-official/cool-admin-go/modules/space v1.5.9
github.com/cool-team-official/cool-admin-go/modules/task v1.5.9
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3
github.com/gogf/gf/v2 v2.6.3
)

require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/glebarez/sqlite v1.10.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gogf/gf v1.16.9 // indirect
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6 // indirect
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.3 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/redis/go-redis/v9 v9.3.0 // indirect
github.com/redis/go-redis/v9 v9.4.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/robfig/cron v1.2.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect
go.opentelemetry.io/otel v1.23.1 // indirect
go.opentelemetry.io/otel/metric v1.23.1 // indirect
go.opentelemetry.io/otel/sdk v1.23.1 // indirect
go.opentelemetry.io/otel/trace v1.23.1 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.2 // indirect
gorm.io/gorm v1.25.5 // indirect
modernc.org/libc v1.30.0 // indirect
gorm.io/driver/mysql v1.5.4 // indirect
gorm.io/gorm v1.25.7 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.27.0 // indirect
modernc.org/sqlite v1.29.1 // indirect
)
Loading

0 comments on commit 9e2fa94

Please sign in to comment.