From eed4abbebf1d412c2a1ffe233cb6b01671049f5c Mon Sep 17 00:00:00 2001 From: liuhuapiaoyuan <278780765@qq.com> Date: Sun, 3 Mar 2024 02:00:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/index.go | 37 ++++++++-------- api/session.go | 4 +- backend-api/backend-api.go | 4 +- backend-api/me.go | 6 +-- backend-api/next_data_gpts_fixed.go | 43 ++++++++++++++++--- config.yaml | 3 +- frontend/stats.html | 2 +- .../template/0qzbhV8iuN7gm3Mz5VXc9/chat.html | 1 + .../0qzbhV8iuN7gm3Mz5VXc9/discovery.html | 1 + .../0qzbhV8iuN7gm3Mz5VXc9/editor.html | 1 + .../template/0qzbhV8iuN7gm3Mz5VXc9/g.html | 1 + .../template/0qzbhV8iuN7gm3Mz5VXc9/gc.html | 1 + .../template/0qzbhV8iuN7gm3Mz5VXc9/gpts.html | 1 + .../template/0qzbhV8iuN7gm3Mz5VXc9/mine.html | 1 + .../template/0qzbhV8iuN7gm3Mz5VXc9/slug.html | 1 + .../template/CdVKBysnaJNkqh_-wcfYZ/chat.html | 1 + .../CdVKBysnaJNkqh_-wcfYZ/discovery.html | 1 + .../CdVKBysnaJNkqh_-wcfYZ/editor.html | 1 + .../template/CdVKBysnaJNkqh_-wcfYZ/g.html | 1 + .../template/CdVKBysnaJNkqh_-wcfYZ/gc.html | 1 + .../template/CdVKBysnaJNkqh_-wcfYZ/gpts.html | 1 + .../template/CdVKBysnaJNkqh_-wcfYZ/mine.html | 1 + .../template/CdVKBysnaJNkqh_-wcfYZ/slug.html | 1 + 23 files changed, 82 insertions(+), 33 deletions(-) create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/chat.html create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/discovery.html create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/editor.html create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/g.html create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/gc.html create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/gpts.html create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/mine.html create mode 100644 resource/template/0qzbhV8iuN7gm3Mz5VXc9/slug.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/chat.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/discovery.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/editor.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/g.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/gc.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/gpts.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/mine.html create mode 100644 resource/template/CdVKBysnaJNkqh_-wcfYZ/slug.html diff --git a/api/index.go b/api/index.go index 8e72499..2a715b1 100644 --- a/api/index.go +++ b/api/index.go @@ -24,8 +24,8 @@ func Index(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -86,8 +86,8 @@ func C(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -142,8 +142,8 @@ func Gpts(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -195,8 +195,8 @@ func Discovery(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -249,8 +249,8 @@ func Editor(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -311,8 +311,8 @@ func Slug(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -370,8 +370,8 @@ func G(r *ghttp.Request) { "gizmo": null, "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -411,7 +411,6 @@ func G(r *ghttp.Request) { }) } -// GC 游戏会话 func GC(r *ghttp.Request) { if r.Session.MustGet("offical-session").IsEmpty() { @@ -428,8 +427,8 @@ func GC(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", @@ -485,8 +484,8 @@ func Mine(r *ghttp.Request) { "pageProps": { "user": { "id": "user-xyhelper", - "name": "admin@openai.com", - "email": "admin@openai.com", + "name": "admin@closeai.com", + "email": "admin@closeai.com", "image": "/avatars.png", "picture": "/avatars.png", "idp": "auth0", diff --git a/api/session.go b/api/session.go index e84c2ed..8154b10 100644 --- a/api/session.go +++ b/api/session.go @@ -42,7 +42,7 @@ func Session(r *ghttp.Request) { sessionJson.Set("accessToken", record["officialSession"].String()) service.AccessTokenCache.Set(ctx, userToken.String(), sessionJson.Get("accessToken").String(), 10*24*time.Hour) sessionJson.Set("accessToken", userToken.String()) - sessionJson.Set("user.email", "admin@openai.com") + sessionJson.Set("user.email", "admin@closeai.com") sessionJson.Set("user.name", expireTime) sessionJson.Set("user.image", "/avatars.png") sessionJson.Set("user.picture", "/avatars.png") @@ -85,7 +85,7 @@ func Session(r *ghttp.Request) { service.AccessTokenCache.Set(ctx, userToken.String(), sessionJson.Get("accessToken").String(), 10*24*time.Hour) sessionJson.Set("accessToken", userToken.String()) - sessionJson.Set("user.email", "admin@openai.com") + sessionJson.Set("user.email", "admin@closeai.com") sessionJson.Set("user.name", expireTime) sessionJson.Set("user.image", "/avatars.png") sessionJson.Set("user.picture", "/avatars.png") diff --git a/backend-api/backend-api.go b/backend-api/backend-api.go index c003a7f..ab7e04b 100644 --- a/backend-api/backend-api.go +++ b/backend-api/backend-api.go @@ -30,7 +30,7 @@ func init() { s := g.Server() s.BindHandler("/backend-api/*any", ProxyAll) // s.BindHandler("/public-api/*any", ProxyAll) - // s.BindHandler("/_next/data/*any", NextDataGptsFixed) + //s.BindHandler("/_next/data/*any", NextDataGptsFixed) backendGroup := s.Group("/backend-api") backendGroup.POST("/accounts/data_export", NotFound) // 禁用导出 backendGroup.POST("/payments/checkout", NotFound) // 禁用支付 @@ -109,7 +109,7 @@ func ProxyAll(r *ghttp.Request) { } // 判断response的Cotnent-Type是否是json - if response.Header.Get("Content-Type") == "application/json" { + if strings.Contains(response.Header.Get("Content-Type"), "json") { isStream = false } if isCreateConversation { diff --git a/backend-api/me.go b/backend-api/me.go index 01a45cb..0d3ec17 100644 --- a/backend-api/me.go +++ b/backend-api/me.go @@ -54,11 +54,11 @@ func Me(r *ghttp.Request) { return } resJson := gjson.New(resStr) - resJson.Set("email", "admin@openai.com") + resJson.Set("email", "__mirror@closeai.com") resJson.Set("name", record["user_username"].String()) resJson.Set("picture", "/avatars.png") - resJson.Set("phone_number", "+1911") - resJson.Set("orgs.data.0.description", "OpenAI") + resJson.Set("phone_number", "+1911011") + resJson.Set("orgs.data.0.description", "closeai") // resJson.Dump() r.Response.WriteJson(resJson) } diff --git a/backend-api/next_data_gpts_fixed.go b/backend-api/next_data_gpts_fixed.go index 9500576..10843aa 100644 --- a/backend-api/next_data_gpts_fixed.go +++ b/backend-api/next_data_gpts_fixed.go @@ -1,14 +1,47 @@ package backendapi import ( - "github.com/gogf/gf/v2/encoding/gjson" + "chatgpt-mirror-server/config" + "crypto/tls" + "net/http" + "net/http/httputil" + "net/url" + + "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" ) func NextDataGptsFixed(r *ghttp.Request) { + ctx := r.GetCtx() + + // 如果请求包含gizmoId + gizmoId := r.Request.URL.Query().Get("gizmoId") + if gizmoId != "" { + UpStream := config.CHATPROXY(ctx) + u, _ := url.Parse(UpStream) + proxy := httputil.NewSingleHostReverseProxy(u) + proxy.Transport = &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + proxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, e error) { + g.Log().Error(ctx, e) + writer.WriteHeader(http.StatusBadGateway) + } + newreq := r.Request.Clone(ctx) + newreq.URL.Host = u.Host + newreq.URL.Scheme = u.Scheme + newreq.Host = u.Host + newreq.Header.Set("authkey", config.AUTHKEY(ctx)) + + newreq.Header.Set("Host", "chat.openai.com") + newreq.Header.Set("Origin", "https://chat.openai.com/chat") + proxy.ServeHTTP(r.Response.Writer.RawWriter(), newreq) + return + + } - resJson := gjson.New(` - { } -`) - r.Response.WriteJson(resJson) + // r.Response.Header().Set("X-Client-Source", "explorer") + // r.Response.Header().Set("X-Middleware-Skip", "1") + // r.Response.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With") + // r.Response.Write(`{}`) } diff --git a/config.yaml b/config.yaml index 1b0bd78..50f8326 100644 --- a/config.yaml +++ b/config.yaml @@ -65,5 +65,6 @@ ONLYTOKEN: false CDNHOST: "https://file.chatgpt.ggss.club" ASSET_PREFIX: "https://cdn.chatgpt.ggss.club" # websocket服务地址 -WS_SERVICE: "ws://127.0.0.1:7999" +WS_SERVICE: "wss://chatgpt.ggss.club/ws" +#WS_SERVICE: "ws://127.0.0.1:7999" # 5a07e29c-31d8-4976-ba66-f183598587d9 diff --git a/frontend/stats.html b/frontend/stats.html index f867be5..364d9cd 100644 --- a/frontend/stats.html +++ b/frontend/stats.html @@ -6157,7 +6157,7 @@