Skip to content

Commit

Permalink
fix: 修复一些语法错误
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhuapiaoyuan committed May 14, 2024
1 parent 48605c3 commit bc253e9
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Session(r *ghttp.Request) {
refreshFlag = expires.Before(time.Now())
}

getSessionUrl := config.CHATPROXY(ctx) + "/getsession"
getSessionUrl := config.CHATPROXY + "/getsession"
// 判断是否过期
if refreshFlag {
g.Log().Info(ctx, "session 过期,重新获取")
Expand Down
2 changes: 1 addition & 1 deletion api/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func Share(r *ghttp.Request) {
ctx := r.GetCtx()
UpStream := config.CHATPROXY(ctx)
UpStream := config.CHATPROXY
// 分享按钮
buttonContent := "Get started with <span class=\"font-bold\">ChatGPT</span>"

Expand Down
2 changes: 1 addition & 1 deletion backend-api/accounts/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Check(r *ghttp.Request) {
// client.SetHeader("Authorization", authHeader)
// client.SetHeader("authkey", config.AUTHKEY(ctx))

// res := client.GetVar(ctx, config.CHATPROXY(ctx)+"/backend-api/accounts/check/v4-2023-04-27")
// res := client.GetVar(ctx, config.CHATPROXY+"/backend-api/accounts/check/v4-2023-04-27")
// resJson := gjson.New(res)
jsonStr := `{
"accounts": {
Expand Down
6 changes: 4 additions & 2 deletions backend-api/backend-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcache"
)

var (
ChatgptSessionService = service.NewChatgptSessionService()
AccessTokenCache = gcache.New()
)

func init() {
Expand Down Expand Up @@ -62,7 +64,7 @@ func ProxyRequestGet(path string, r *ghttp.Request) (resStr string, err error) {
}
_, _, accessToken, err := ChatgptSessionService.GetAccessToken(ctx, userToken)

UpStream := config.CHATPROXY(ctx)
UpStream := config.CHATPROXY
if err != nil {
// 处理错误
panic(err)
Expand Down Expand Up @@ -142,7 +144,7 @@ func ProxyAll(r *ghttp.Request) {
WsUpStream := config.WS_SERVICE(ctx)
// g.Log().Info(ctx, "ProxyBackendApi:", path)
proxy := &httputil.ReverseProxy{}
UpStream := config.CHATPROXY(ctx)
UpStream := config.CHATPROXY

proxy.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
Expand Down
4 changes: 2 additions & 2 deletions backend-api/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func Me(r *ghttp.Request) {
g.Log().Error(ctx, err)
r.Response.WriteStatus(http.StatusUnauthorized)
return
}
}
resStr, err := ProxyRequestGet("/backend-api/me", r)

// UpStream := config.CHATPROXY(ctx)
// UpStream := config.CHATPROXY
// // 请求后端接口
// res, err := g.Client().SetHeaderMap(map[string]string{
// "Authorization": "Bearer " + AccessToken,
Expand Down
2 changes: 1 addition & 1 deletion backend-api/next_data_gpts_fixed.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NextDataGptsFixed(r *ghttp.Request) {
// 如果请求包含gizmoId
gizmoId := r.Request.URL.Query().Get("gizmoId")
if gizmoId != "" {
UpStream := config.CHATPROXY(ctx)
UpStream := config.CHATPROXY
u, _ := url.Parse(UpStream)
proxy := httputil.NewSingleHostReverseProxy(u)
proxy.Transport = &http.Transport{
Expand Down
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ modules:
enable: 1

# 接入网关地址
CHATPROXY: "https://chat.openai.com"
#JA3_PROXY: "http://a:[email protected]:9988"
# CHATPROXY: "https://chat.openai.com"
JA3_PROXY: "http://a:[email protected]:9988"
#CHATPROXY: "http://host.docker.internal:7999"
#CHATPROXY: "https://chatgpt.ggss.club/gateway"
#ARKOSE_URL: "https://chatgpt.ggss.club/arkose/v2/"
Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/gogf/gf/v2/util/gconv"
)

func CHATPROXY(ctx g.Ctx) string {
return g.Cfg().MustGetWithEnv(ctx, "CHATPROXY").String()
}
// func CHATPROXY(ctx g.Ctx) string {
// return g.Cfg().MustGetWithEnv(ctx, "CHATPROXY").String()
// }
func WS_SERVICE(ctx g.Ctx) string {
return g.Cfg().MustGetWithEnv(ctx, "WS_SERVICE").String()
}
Expand Down
4 changes: 2 additions & 2 deletions modules/chatgpt/service/chatgpt_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *ChatgptSessionService) ModifyAfter(ctx g.Ctx, method string, param map[
officialSession := param["officialSession"]
if officialSession == "" {
g.Log().Debug(ctx, "ChatgptSessionService.ModifyAfter", "officialSession is empty")
getSessionUrl := config.CHATPROXY(ctx) + "/getsession"
getSessionUrl := config.CHATPROXY + "/getsession"
sessionVar := g.Client().SetHeader("authkey", config.AUTHKEY(ctx)).SetCookie("arkoseToken", gconv.String(param["arkoseToken"])).PostVar(ctx, getSessionUrl, g.Map{
"username": param["email"],
"password": param["password"],
Expand Down Expand Up @@ -91,7 +91,7 @@ func (s *ChatgptSessionService) ModifyAfter(ctx g.Ctx, method string, param map[

// 写一个函数 刷新数据
func (s *ChatgptSessionService) RefreshSession(ctx g.Ctx, chatgpt_session gdb.Record) (err error) {
getSessionUrl := config.CHATPROXY(ctx) + "/getsession"
getSessionUrl := config.CHATPROXY + "/getsession"
sessionVar := g.Client().SetHeader("authkey", config.AUTHKEY(ctx)).PostVar(ctx, getSessionUrl, g.Map{
"username": chatgpt_session["email"],
"password": chatgpt_session["password"],
Expand Down
3 changes: 0 additions & 3 deletions modules/chatgpt/tasks/refresh_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ func RefreshSession(ctx g.Ctx) {
continue
}

getSessionUrl := config.CHATPROXY(ctx) + "/getsession"
refreshCookie := gjson.New(v["officialSession"]).Get("refreshCookie").String()

sessionVar := g.Client().SetHeader("authkey", config.AUTHKEY(ctx)).PostVar(ctx, getSessionUrl, g.Map{
"username": v["email"],
"password": v["password"],
Expand Down
1 change: 1 addition & 0 deletions public-api/proxypublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
backendapi "chatgpt-mirror-server/backend-api"
"chatgpt-mirror-server/config"
"chatgpt-mirror-server/utility"
"crypto/tls"
"net/http"
"net/http/httputil"
"net/url"
Expand Down

0 comments on commit bc253e9

Please sign in to comment.