Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 提取基础请求头,普号TurnStile不做缓存。

* Update tag_name in build.yml to v2.0.6

* 补全伪装环境参数

* Fix content-type header in POSTconversation function

* fix

---------

Co-authored-by: xiaozhou26 <xiaoxiaofeihh@foxmail.com>
Co-authored-by: xiaofei <122727418+xiaozhou26@users.noreply.github.com>
  • Loading branch information
3 people committed May 8, 2024
1 parent 8b68be0 commit f067878
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 91 deletions.
29 changes: 29 additions & 0 deletions httpclient/bogdanfinn/tls_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"aurora/httpclient"
"io"
"net/http"
"net/url"

fhttp "github.com/bogdanfinn/fhttp"
tls_client "github.com/bogdanfinn/tls-client"
Expand Down Expand Up @@ -99,3 +100,31 @@ func (t *TlsClient) Request(method httpclient.HttpMethod, url string, headers ht
func (t *TlsClient) SetProxy(url string) error {
return t.Client.SetProxy(url)
}

func (t *TlsClient) SetCookies(rawUrl string, cookies []*http.Cookie) {
if cookies == nil {
return
}
u, err := url.Parse(rawUrl)
if err != nil {
return
}
var fcookies []*fhttp.Cookie
for _, c := range cookies {
fcookies = append(fcookies, &fhttp.Cookie{
Name: c.Name,
Value: c.Value,
Path: c.Path,
Domain: c.Domain,
Expires: c.Expires,
RawExpires: c.RawExpires,
MaxAge: c.MaxAge,
Secure: c.Secure,
HttpOnly: c.HttpOnly,
SameSite: fhttp.SameSite(c.SameSite),
Raw: c.Raw,
Unparsed: c.Unparsed,
})
}
t.Client.GetCookieJar().SetCookies(u, fcookies)
}
13 changes: 10 additions & 3 deletions initialize/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import (
chatgpt_types "aurora/typings/chatgpt"
officialtypes "aurora/typings/official"
"aurora/util"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"io"
"os"
"strings"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
)

type Handler struct {
Expand All @@ -40,6 +39,7 @@ func (h *Handler) refresh(c *gin.Context) {
}
proxyUrl := h.proxy.GetProxyIP()
client := bogdanfinn.NewStdClient()
client.Client.GetCookieJar()
openaiRefreshToken, status, err := chatgpt.GETTokenForRefreshToken(client, refreshToken.RefreshToken, proxyUrl)
if err != nil {
c.JSON(400, gin.H{
Expand All @@ -53,6 +53,12 @@ func (h *Handler) refresh(c *gin.Context) {
c.JSON(status, openaiRefreshToken)
}

func (h *Handler) InitBasicConfigForChatGPT() {
proxy_url := h.proxy.GetProxyIP()
client := bogdanfinn.NewStdClient()
chatgpt.GetDpl(client, proxy_url)
}

func (h *Handler) session(c *gin.Context) {
var sessionToken officialtypes.OpenAISessionToken
err := c.BindJSON(&sessionToken)
Expand Down Expand Up @@ -175,6 +181,7 @@ func (h *Handler) nightmare(c *gin.Context) {

uid := uuid.NewString()
client := bogdanfinn.NewStdClient()
client.SetCookies("https://chatgpt.com", chatgpt.BasicCookies)
turnStile, status, err := chatgpt.InitTurnStile(client, secret, proxyUrl)
if err != nil {
c.JSON(status, gin.H{
Expand Down
3 changes: 3 additions & 0 deletions initialize/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ func RegisterRouter() *gin.Engine {
readAccessToken(),
)

// 初始化基础前置参数
handler.InitBasicConfigForChatGPT()

router := gin.Default()
router.Use(middlewares.Cors)

Expand Down
Loading

0 comments on commit f067878

Please sign in to comment.