From 590c556631c3ba70a94ba02b5165163ae0323740 Mon Sep 17 00:00:00 2001 From: GCSLaoLi Date: Fri, 12 Apr 2024 08:40:52 -0400 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E7=82=B9=E5=B9=B2?= =?UTF-8?q?=E5=87=80IP=E4=B8=8B=E7=9A=84=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend-anon/backend-anon.go | 11 ++++++----- backend-api/backend-api.go | 14 ++++++++++++-- backend-api/proxybackendapi.go | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/backend-anon/backend-anon.go b/backend-anon/backend-anon.go index 5863649..1970812 100644 --- a/backend-anon/backend-anon.go +++ b/backend-anon/backend-anon.go @@ -30,11 +30,12 @@ func PromptLibrary(r *ghttp.Request) { limit := r.Get("limit").String() offset := r.Get("offset").String() ProxyClient := gclient.New().Proxy(config.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", - "OAI-Language": r.Header.Get("OAI-Language"), + "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", + "OAI-Language": r.Header.Get("OAI-Language"), + "OAI-Device-Id": r.Header.Get("OAI-Device-Id"), }) res, err := ProxyClient.Get(ctx, "https://chat.openai.com/backend-anon/prompt_library/", g.Map{"limit": limit, "offset": offset}) if err != nil { diff --git a/backend-api/backend-api.go b/backend-api/backend-api.go index c584e66..7b03ef6 100644 --- a/backend-api/backend-api.go +++ b/backend-api/backend-api.go @@ -23,15 +23,25 @@ func Init(ctx g.Ctx) { // /backend-api/prompt_library/ func PromptLibrary(r *ghttp.Request) { ctx := r.Context() + userToken := r.Session.MustGet("userToken").String() + if userToken == "" { + r.Response.Status = 401 + r.Response.WriteJson(g.Map{"detail": "Unauthorized"}) + } limit := r.Get("limit").String() offset := r.Get("offset").String() - ProxyClient := gclient.New().Proxy(config.Ja3Proxy.String()).SetBrowserMode(true).SetHeaderMap(g.MapStrStr{ + headerMap := 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", "OAI-Language": r.Header.Get("OAI-Language"), - }) + } + accessToken := config.GetAccessToken(ctx) + if accessToken != "" { + headerMap["Authorization"] = "Bearer " + accessToken + } + ProxyClient := gclient.New().Proxy(config.Ja3Proxy.String()).SetBrowserMode(true).SetHeaderMap(headerMap) res, err := ProxyClient.Get(ctx, "https://chat.openai.com/backend-api/prompt_library/", g.Map{"limit": limit, "offset": offset}) if err != nil { g.Log().Error(ctx, err) diff --git a/backend-api/proxybackendapi.go b/backend-api/proxybackendapi.go index 72c9257..3b5fe60 100644 --- a/backend-api/proxybackendapi.go +++ b/backend-api/proxybackendapi.go @@ -71,7 +71,7 @@ func ProxyBackendApi(r *ghttp.Request) { header := r.Request.Header header.Set("Origin", "https://chat.openai.com") header.Set("Referer", "https://chat.openai.com/") - header.Del("Cookie") + // header.Del("Cookie") header.Del("Accept-Encoding") accessToken := config.GetAccessToken(ctx) if accessToken != "" {