auto refresh puid
This commit is contained in:
parent
7b9b3522b3
commit
61cfd9c806
2
go.mod
2
go.mod
@ -3,6 +3,7 @@ module freechatgpt
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/acheong08/OpenAIAuth v0.0.0-20230530050836-f2a06cd52911
|
||||
github.com/acheong08/endless v0.0.0-20230529075213-74050cf641c8
|
||||
github.com/bogdanfinn/fhttp v0.5.22
|
||||
github.com/bogdanfinn/tls-client v1.3.12
|
||||
@ -28,6 +29,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
|
||||
github.com/tam7t/hpkp v0.0.0-20160821193359-2b70b4024ed5 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/acheong08/OpenAIAuth v0.0.0-20230530050836-f2a06cd52911 h1:KNdCGjt2DkrFn4RNS6Uh41rHwyD6dUhYxYuhVFxsZkc=
|
||||
github.com/acheong08/OpenAIAuth v0.0.0-20230530050836-f2a06cd52911/go.mod h1:ES3Dh9hnbR2mDPlNTagj5e3b4nXECd4tbAjVgxggXEE=
|
||||
github.com/acheong08/endless v0.0.0-20230529075213-74050cf641c8 h1:mHtMoGlGNUfMRjsWcb5Kvd1mJfJG8Gr1TtIghE8iiN8=
|
||||
github.com/acheong08/endless v0.0.0-20230529075213-74050cf641c8/go.mod h1:0yO7neMeJLvKk/B/fq5votDY8rByrOPDubpvU+6saKo=
|
||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
@ -54,6 +56,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c h1:4RYnE0ISVwRxm9Dfo7utw1dh0kdRDEmVYq2MFVLy5zI=
|
||||
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c/go.mod h1:DvuJJ/w1Y59rG8UTDxsMk5U+UJXJwuvUgbiJSm9yhX8=
|
||||
github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us=
|
||||
github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
@ -14,6 +14,15 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func openaiHandler(c *gin.Context) {
|
||||
err := c.BindJSON(&authorizations)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": "JSON invalid"})
|
||||
}
|
||||
os.Setenv("OPENAI_EMAIL", authorizations.OpenAI_Email)
|
||||
os.Setenv("OPENAI_PASSWORD", authorizations.OpenAI_Password)
|
||||
}
|
||||
|
||||
func passwordHandler(c *gin.Context) {
|
||||
// Get the password from the request (json) and update the password
|
||||
type password_struct struct {
|
||||
|
31
main.go
31
main.go
@ -3,9 +3,12 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"freechatgpt/internal/tokens"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/acheong08/OpenAIAuth/auth"
|
||||
"github.com/acheong08/endless"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -14,7 +17,33 @@ var HOST string
|
||||
var PORT string
|
||||
var ACCESS_TOKENS tokens.AccessToken
|
||||
|
||||
var authorizations struct {
|
||||
OpenAI_Email string `json:"openai_email"`
|
||||
OpenAI_Password string `json:"openai_password"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
authorizations.OpenAI_Email = os.Getenv("OPENAI_EMAIL")
|
||||
authorizations.OpenAI_Password = os.Getenv("OPENAI_PASSWORD")
|
||||
if authorizations.OpenAI_Email != "" && authorizations.OpenAI_Password != "" {
|
||||
go func() {
|
||||
for {
|
||||
authenticator := auth.NewAuthenticator(authorizations.OpenAI_Email, authorizations.OpenAI_Password, os.Getenv("http_proxy"))
|
||||
err := authenticator.Begin()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
break
|
||||
}
|
||||
puid, err := authenticator.GetPUID()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
os.Setenv("PUID", puid)
|
||||
println(puid)
|
||||
time.Sleep(24 * time.Hour * 7)
|
||||
}
|
||||
}()
|
||||
}
|
||||
HOST = os.Getenv("SERVER_HOST")
|
||||
PORT = os.Getenv("SERVER_PORT")
|
||||
if HOST == "" {
|
||||
@ -52,7 +81,6 @@ func init() {
|
||||
ACCESS_TOKENS = tokens.NewAccessToken(token_list)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
router := gin.Default()
|
||||
|
||||
@ -71,6 +99,7 @@ func main() {
|
||||
admin_routes.PATCH("/password", passwordHandler)
|
||||
admin_routes.PATCH("/tokens", tokensHandler)
|
||||
admin_routes.PATCH("/puid", puidHandler)
|
||||
admin_routes.PATCH("/openai", openaiHandler)
|
||||
/// Public routes
|
||||
router.OPTIONS("/v1/chat/completions", optionsHandler)
|
||||
router.POST("/v1/chat/completions", Authorization, nightmare)
|
||||
|
Reference in New Issue
Block a user