From 85c7e2deb9bcbc22e5927f3234d35b6fe19fb109 Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 18 Apr 2023 18:06:42 +0800 Subject: [PATCH] default to proxy --- internal/chatgpt/request.go | 57 ++++++++++++++++++------------------- tools/authenticator/go.mod | 20 ++++++------- tools/authenticator/go.sum | 20 +++++++++++++ 3 files changed, 58 insertions(+), 39 deletions(-) diff --git a/internal/chatgpt/request.go b/internal/chatgpt/request.go index e34fe55..54cdd67 100644 --- a/internal/chatgpt/request.go +++ b/internal/chatgpt/request.go @@ -1,11 +1,9 @@ package chatgpt import ( - "bufio" "bytes" "encoding/json" "math/rand" - "os" typings "freechatgpt/internal/typings" @@ -23,42 +21,43 @@ var ( tls_client.WithNotFollowRedirects(), tls_client.WithCookieJar(jar), // create cookieJar instance and pass it as argument } - client, _ = tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...) - http_proxy = os.Getenv("http_proxy") - API_REVERSE_PROXY = os.Getenv("API_REVERSE_PROXY") + client, _ = tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...) + // http_proxy = os.Getenv("http_proxy") + // API_REVERSE_PROXY = os.Getenv("API_REVERSE_PROXY") ) -func init() { - // Check for proxies.txt - if _, err := os.Stat("proxies.txt"); err == nil { - // Each line is a proxy, put in proxies array - file, _ := os.Open("proxies.txt") - defer file.Close() - scanner := bufio.NewScanner(file) - for scanner.Scan() { - proxy := "socks5://" + scanner.Text() - proxies = append(proxies, proxy) - } - } -} +// func init() { +// // Check for proxies.txt +// if _, err := os.Stat("proxies.txt"); err == nil { +// // Each line is a proxy, put in proxies array +// file, _ := os.Open("proxies.txt") +// defer file.Close() +// scanner := bufio.NewScanner(file) +// for scanner.Scan() { +// proxy := "socks5://" + scanner.Text() +// proxies = append(proxies, proxy) +// } +// } +// } func random_int(min int, max int) int { return min + rand.Intn(max-min) } func SendRequest(message typings.ChatGPTRequest, puid *string, access_token string) (*http.Response, error) { - if http_proxy != "" && len(proxies) > 0 { - client.SetProxy(http_proxy) - } - // Take random proxy from proxies.txt - if len(proxies) > 0 { - client.SetProxy(proxies[random_int(0, len(proxies)-1)]) - } + // if http_proxy != "" && len(proxies) > 0 { + // client.SetProxy(http_proxy) + // } + // // Take random proxy from proxies.txt + // if len(proxies) > 0 { + // client.SetProxy(proxies[random_int(0, len(proxies)-1)]) + // } - apiUrl := "https://chat.openai.com/backend-api/conversation" - if API_REVERSE_PROXY != "" { - apiUrl = API_REVERSE_PROXY - } + apiUrl := "https://ai.fakeopen.com/api/conversation" + // if API_REVERSE_PROXY != "" { + // apiUrl = API_REVERSE_PROXY + // } + println(apiUrl) // JSONify the body and add it to the request body_json, err := json.Marshal(message) diff --git a/tools/authenticator/go.mod b/tools/authenticator/go.mod index 689a258..69f223c 100644 --- a/tools/authenticator/go.mod +++ b/tools/authenticator/go.mod @@ -2,17 +2,17 @@ module authenticator go 1.20 -require github.com/acheong08/OpenAIAuth v0.0.0-20230404125145-978e2599a89b +require github.com/acheong08/OpenAIAuth v0.0.0-20230418032326-62be4d65e31f require ( - github.com/andybalholm/brotli v1.0.4 // indirect - github.com/bogdanfinn/fhttp v0.5.19 // indirect - github.com/bogdanfinn/tls-client v1.3.8 // indirect - github.com/bogdanfinn/utls v1.5.15 // indirect - github.com/klauspost/compress v1.15.12 // indirect + github.com/andybalholm/brotli v1.0.5 // indirect + github.com/bogdanfinn/fhttp v0.5.20 // indirect + github.com/bogdanfinn/tls-client v1.3.9 // indirect + github.com/bogdanfinn/utls v1.5.16 // indirect + github.com/klauspost/compress v1.16.5 // indirect github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5 // indirect - golang.org/x/crypto v0.1.0 // indirect - golang.org/x/net v0.1.0 // indirect - golang.org/x/sys v0.1.0 // indirect - golang.org/x/text v0.4.0 // indirect + golang.org/x/crypto v0.8.0 // indirect + golang.org/x/net v0.9.0 // indirect + golang.org/x/sys v0.7.0 // indirect + golang.org/x/text v0.9.0 // indirect ) diff --git a/tools/authenticator/go.sum b/tools/authenticator/go.sum index 2840e4f..ab0f985 100644 --- a/tools/authenticator/go.sum +++ b/tools/authenticator/go.sum @@ -1,22 +1,42 @@ github.com/acheong08/OpenAIAuth v0.0.0-20230404125145-978e2599a89b h1:QMz1U9SIFI5EOIIEoHv2MkjsZ/B+Kmk22IoVh6f7OLw= github.com/acheong08/OpenAIAuth v0.0.0-20230404125145-978e2599a89b/go.mod h1:+ONo6ErsoP7zxRfsCva6REyOT7fUEKPNHcxd/JczrKI= +github.com/acheong08/OpenAIAuth v0.0.0-20230418032326-62be4d65e31f h1:YUzPkmv4AcVjVG6cKdxocBDHUrDeuYjBETPHFVj0TjI= +github.com/acheong08/OpenAIAuth v0.0.0-20230418032326-62be4d65e31f/go.mod h1:+ONo6ErsoP7zxRfsCva6REyOT7fUEKPNHcxd/JczrKI= github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= +github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/bogdanfinn/fhttp v0.5.19 h1:/FKuFAtSw3+iZyNkaWXRDSVqMmOvThDjXanlG6/DXos= github.com/bogdanfinn/fhttp v0.5.19/go.mod h1:emv9FntlC5eAyrIUhCi6oC5NLoBC9d4AJLCq2T1bobY= +github.com/bogdanfinn/fhttp v0.5.20 h1:joQrA0tVFBQNQ8BbKRmIM972GfawXA+qbCRQlX6dauQ= +github.com/bogdanfinn/fhttp v0.5.20/go.mod h1:brqi5woc5eSCVHdKYBV8aZLbO7HGqpwyDLeXW+fT18I= github.com/bogdanfinn/tls-client v1.3.8 h1:HIucpArqyqOUIN/7MDJJA9Ngt+lKHUyoQ2y2CUjIDNM= github.com/bogdanfinn/tls-client v1.3.8/go.mod h1:dMt6v22wNyA1Y4e3Us6jK3lC64Y6FE2cziydZ7pGK3A= +github.com/bogdanfinn/tls-client v1.3.9 h1:y/+ZOxIJG0E8ErQ1CONI0xDqS+5mW3z0gg9ylfFDLAQ= +github.com/bogdanfinn/tls-client v1.3.9/go.mod h1:XILFibmi++kIcIREyZTLtlAQ+9nz9iqjgcKaoaO+7t8= github.com/bogdanfinn/utls v1.5.15 h1:XUUMJZh2AptaouuwUrc/RQOYgyV89rstC5Nj3FSP43s= github.com/bogdanfinn/utls v1.5.15/go.mod h1:mHeRCi69cUiEyVBkKONB1cAbLjRcZnlJbGzttmiuK4o= +github.com/bogdanfinn/utls v1.5.16 h1:NhhWkegEcYETBMj9nvgO4lwvc6NcLH+znrXzO3gnw4M= +github.com/bogdanfinn/utls v1.5.16/go.mod h1:mHeRCi69cUiEyVBkKONB1cAbLjRcZnlJbGzttmiuK4o= github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= +github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5 h1:YqAladjX7xpA6BM04leXMWAEjS0mTZ5kUU9KRBriQJc= github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5/go.mod h1:2JjD2zLQYH5HO74y5+aE3remJQvl6q4Sn6aWA2wD1Ng= golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= +golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= +golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=