Skip to content

Commit

Permalink
修复一点干净IP下的小问题
Browse files Browse the repository at this point in the history
  • Loading branch information
gcslaoli committed Apr 12, 2024
1 parent bc44ddd commit 590c556
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 6 additions & 5 deletions backend-anon/backend-anon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 12 additions & 2 deletions backend-api/backend-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend-api/proxybackendapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down

0 comments on commit 590c556

Please sign in to comment.