default to proxy
This commit is contained in:
parent
937bb23cd8
commit
85c7e2deb9
@ -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)
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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=
|
||||
|
Reference in New Issue
Block a user