Skip to content

Commit

Permalink
fix no need cookie & login
Browse files Browse the repository at this point in the history
  • Loading branch information
xqdoo00o committed Jun 11, 2024
1 parent 0058a6a commit 49585a8
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 48 deletions.
2 changes: 1 addition & 1 deletion conversion/requests/chatgpt/convert.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package chatgpt

import (
chatgpt_types "freechatgpt/internal/chatgpt"
"freechatgpt/internal/tokens"
chatgpt_types "freechatgpt/typings/chatgpt"
official_types "freechatgpt/typings/official"
"regexp"
"strings"
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ require (
github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd
github.com/bogdanfinn/fhttp v0.5.28
github.com/bogdanfinn/tls-client v1.7.5
github.com/bogdanfinn/utls v1.6.1
github.com/gin-gonic/gin v1.9.1
github.com/go-resty/resty/v2 v2.12.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.1
github.com/joho/godotenv v1.5.1
github.com/tidwall/gjson v1.17.1
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240520071626-7f9e463abed0
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240611145732-92214e7f4f4c
github.com/xqdoo00o/funcaptcha v0.0.0-20240507071758-6c32cfc34bdc
golang.org/x/crypto v0.23.0
golang.org/x/image v0.15.0
golang.org/x/net v0.25.0
k8s.io/apimachinery v0.29.3
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/bogdanfinn/utls v1.6.1 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudflare/circl v1.3.8 // indirect
Expand All @@ -51,6 +49,7 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.20.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down Expand Up @@ -116,8 +114,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240520071626-7f9e463abed0 h1:pZSFokQ7e5a86B4jD8zn6Js4kLNeTN7sh3InxRSivEs=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240520071626-7f9e463abed0/go.mod h1:TOXe2RBzDx5/w2RYzP7C1WNfNJx1wEVOSkCBcGSaNrM=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240611145732-92214e7f4f4c h1:HRtM9QWrE5IEdCG0s5qD2VloTGKzrCzAeW7QzLFEfEM=
github.com/xqdoo00o/OpenAIAuth v0.0.0-20240611145732-92214e7f4f4c/go.mod h1:TOXe2RBzDx5/w2RYzP7C1WNfNJx1wEVOSkCBcGSaNrM=
github.com/xqdoo00o/funcaptcha v0.0.0-20240507071758-6c32cfc34bdc h1:GA82q8G/mh5LLaBAo3UWw4zvxk/BlarGSuonyK4tz3Y=
github.com/xqdoo00o/funcaptcha v0.0.0-20240507071758-6c32cfc34bdc/go.mod h1:MmsYdzgYjO6NQYNS8vtecBWUFWwD4TApVzMp8iwKiR0=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
34 changes: 0 additions & 34 deletions typings/chatgpt/request.go → internal/chatgpt/reqtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (

http "github.com/bogdanfinn/fhttp"

tls_client "github.com/bogdanfinn/tls-client"
"github.com/bogdanfinn/tls-client/profiles"
"github.com/google/uuid"
)

Expand Down Expand Up @@ -120,22 +118,11 @@ type RetrievalResult struct {
}

var (
client, _ = tls_client.NewHttpClient(tls_client.NewNoopLogger(), []tls_client.HttpClientOption{
tls_client.WithCookieJar(tls_client.NewCookieJar()),
tls_client.WithTimeoutSeconds(600),
tls_client.WithClientProfile(profiles.Okhttp4Android13),
}...)
userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
fileHashPool = map[string]*FileResult{}
retrievalMime = map[string]bool{}
)

func init() {
u, _ := url.Parse("https://chatgpt.com")
client.GetCookieJar().SetCookies(u, []*http.Cookie{{
Name: "oai-dm-tgt-c-240329",
Value: "2024-04-02",
}})
// from https://chatgpt.com/backend-api/models?history_and_training_disabled=false models product_features
retrievalMime = map[string]bool{"text/rtf": true, "application/javascript": true, "text/x-tex": true, "text/css": true, "text/xml": true, "message/rfc822": true, "text/javascript": true, "application/rtf": true, "text/x-typescript": true, "application/x-powershell": true, "application/x-sql": true, "text/x-shellscript": true, "text/x-c++": true, "text/markdown": true, "text/x-php": true, "text/x-script.python": true, "text/vbscript": true, "text/x-asm": true, "application/vnd.oasis.opendocument.text": true, "text/x-lisp": true, "application/vnd.openxmlformats-officedocument.wordprocessingml.document": true, "application/x-rust": true, "text/x-diff": true, "text/x-python": true, "application/vnd.apple.keynote": true, "application/vnd.ms-powerpoint": true, "application/x-yaml": true, "application/msword": true, "application/x-scala": true, "text/plain": true, "text/html": true, "application/json": true, "text/calendar": true, "text/x-csharp": true, "text/x-rst": true, "text/x-java": true, "text/x-makefile": true, "application/pdf": true, "text/x-c": true, "text/x-vcard": true, "application/vnd.apple.pages": true, "application/vnd.openxmlformats-officedocument.presentationml.presentation": true, "text/x-ruby": true, "text/x-sh": true}
// from https://chromium.googlesource.com/chromium/src/+/HEAD/net/base/mime_util.cc
Expand Down Expand Up @@ -251,27 +238,6 @@ func NewChatGPTRequest() ChatGPTRequest {
}
}

func newRequest(method string, url string, body io.Reader, secret *tokens.Secret, deviceId string) (*http.Request, error) {
request, err := http.NewRequest(method, url, body)
if err != nil {
return &http.Request{}, err
}
request.Header.Set("User-Agent", userAgent)
request.Header.Set("Accept", "*/*")
request.Header.Set("Oai-Device-Id", deviceId)
request.Header.Set("Oai-Language", "en-US")
if secret.Token != "" {
request.Header.Set("Authorization", "Bearer "+secret.Token)
}
if secret.PUID != "" {
request.Header.Set("Cookie", "_puid="+secret.PUID+";")
}
if secret.TeamUserID != "" {
request.Header.Set("Chatgpt-Account-Id", secret.TeamUserID)
}
return request, nil
}

func processUrl(urlstr string, account string, secret *tokens.Secret, deviceId string, proxy string) *FileResult {
if proxy != "" {
client.SetProxy(proxy)
Expand Down
5 changes: 1 addition & 4 deletions internal/chatgpt/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ func SetOAICookie(uuid string) {
client.GetCookieJar().SetCookies(hostURL, []*http.Cookie{{
Name: "oai-did",
Value: uuid,
}, {
Name: "oai-dm-tgt-c-240329",
Value: "2024-04-02",
}})
}

Expand Down Expand Up @@ -264,7 +261,7 @@ func getURLAttribution(secret *tokens.Secret, deviceId string, url string) strin
return attr.Attribution
}

func POSTconversation(message chatgpt_types.ChatGPTRequest, secret *tokens.Secret, deviceId string, chat_token string, arkoseToken string, proofToken string, proxy string) (*http.Response, error) {
func POSTconversation(message ChatGPTRequest, secret *tokens.Secret, deviceId string, chat_token string, arkoseToken string, proofToken string, proxy string) (*http.Response, error) {
if proxy != "" {
client.SetProxy(proxy)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

chatgpt_types "freechatgpt/typings/chatgpt"
chatgpt_types "freechatgpt/internal/chatgpt"

"github.com/acheong08/endless"
"github.com/gin-gonic/gin"
Expand Down

0 comments on commit 49585a8

Please sign in to comment.