Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lagrange): 动态拉取sign反代 #1181

Merged
merged 9 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/api_bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ func Bind(e *echo.Echo, _myDice *dice.DiceManager) {
e.POST(prefix+"/im_connections/del", ImConnectionsDel)
e.POST(prefix+"/im_connections/set_enable", ImConnectionsSetEnable)
e.POST(prefix+"/im_connections/set_data", ImConnectionsSetData)
e.POST(prefix+"/im_connections/set_sign_server", ImConnectionsRWSignServerUrl)
e.GET(prefix+"/im_connections/get_lgr_signinfo", ImConnectionsGetSignInfo)
e.POST(prefix+"/im_connections/gocqhttpRelogin", ImConnectionsGocqhttpRelogin)
e.POST(prefix+"/im_connections/walleQRelogin", ImConnectionsWalleQRelogin)
e.GET(prefix+"/im_connections/gocq_config_download.zip", ImConnectionsGocqConfigDownload)
Expand Down
46 changes: 10 additions & 36 deletions api/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,46 +137,18 @@ func ImConnectionsSetData(c echo.Context) error {
return c.JSON(http.StatusNotFound, nil)
}

func ImConnectionsRWSignServerUrl(c echo.Context) error {
func ImConnectionsGetSignInfo(c echo.Context) error {
if !doAuth(c) {
return c.JSON(http.StatusForbidden, nil)
}
if dm.JustForTest {
return c.JSON(http.StatusOK, map[string]interface{}{
"testMode": true,
})
}

v := struct {
ID string `form:"id" json:"id"`
SignServerUrl string `form:"signServerUrl" json:"signServerUrl"`
W bool `form:"w" json:"w"`
SignServerVersion string `form:"signServerVersion" json:"signServerVersion"`
}{}

err := c.Bind(&v)
data, err := dice.LagrangeGetSignInfo(myDice)
if err != nil {
myDice.Save(false)
return c.JSON(http.StatusNotFound, nil)
return Error(&c, "读取SignInfo失败", Response{})
}
for _, i := range myDice.ImSession.EndPoints {
if i.ID != v.ID {
continue
}
if i.ProtocolType == "onebot" {
pa := i.Adapter.(*dice.PlatformAdapterGocq)
if pa.BuiltinMode == "lagrange" || pa.BuiltinMode == "lagrange-gocq" {
signServerUrl, signServerVersion := dice.RWLagrangeSignServerUrl(myDice, i, v.SignServerUrl, v.W, v.SignServerVersion)
if signServerUrl != "" {
return Success(&c, Response{
"signServerUrl": signServerUrl,
"signServerVersion": signServerVersion,
})
}
}
}
}
return Error(&c, "读取signServerUrl字段失败", Response{})
return Success(&c, Response{
"data": data,
})
}

func ImConnectionsDel(c echo.Context) error {
Expand Down Expand Up @@ -967,7 +939,7 @@ func ImConnectionsAddBuiltinLagrange(c echo.Context) error {

v := struct {
Account string `yaml:"account" json:"account"`
SignServerUrl string `yaml:"signServerUrl" json:"signServerUrl"`
SignServerName string `yaml:"signServerName" json:"signServerName"`
SignServerVersion string `yaml:"signServerVersion" json:"signServerVersion"`
IsGocq bool `yaml:"isGocq" json:"isGocq"`
}{}
Expand All @@ -991,9 +963,11 @@ func ImConnectionsAddBuiltinLagrange(c echo.Context) error {
if err != nil {
return err
}
pa.SignServerName = v.SignServerName
pa.SignServerVer = v.SignServerVersion
dice.LagrangeServe(myDice, conn, dice.LagrangeLoginInfo{
UIN: uin,
SignServerUrl: v.SignServerUrl,
SignServerName: v.SignServerName,
SignServerVersion: v.SignServerVersion,
IsAsyncRun: true,
})
Expand Down
28 changes: 14 additions & 14 deletions dice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2306,20 +2306,20 @@ func (d *Dice) loads() {
d.Config = config

// 1.4.5 版本 - 覆写lagrange配置
for _, i := range d.ImSession.EndPoints {
if i.ProtocolType == "onebot" {
pa := i.Adapter.(*PlatformAdapterGocq)
if pa.BuiltinMode == "lagrange" {
signServerUrl, signServerVersion := RWLagrangeSignServerUrl(d, i, "sealdice", false, "30366")
if signServerUrl != "" {
// 版本为空,覆写为 "30366"
if signServerVersion == "" {
RWLagrangeSignServerUrl(d, i, "sealdice", true, "30366")
}
}
}
}
}
// for _, i := range d.ImSession.EndPoints {
// if i.ProtocolType == "onebot" {
// pa := i.Adapter.(*PlatformAdapterGocq)
// if pa.BuiltinMode == "lagrange" {
// signServerUrl, signServerVersion := RWLagrangeSignServerUrl(d, i, "sealdice", false, "30366")
// if signServerUrl != "" {
// // 版本为空,覆写为 "30366"
// if signServerVersion == "" {
// RWLagrangeSignServerUrl(d, i, "sealdice", true, "30366")
// }
// }
// }
// }
// }

// 设置全局群名缓存和用户名缓存
dm := d.Parent
Expand Down
2 changes: 2 additions & 0 deletions dice/platform_adapter_gocq.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type PlatformAdapterGocq struct {
riskAlertShieldCount int // 风控警告屏蔽次数,一个临时变量
useArrayMessage bool `yaml:"-"` // 使用分段消息
lagrangeRebootTimes int
SignServerVer string `yaml:"signServerVer" json:"signServerVer"` // 用于前端显示
SignServerName string `yaml:"signServerName" json:"signServerName"` // 用于前端显示
}

type Sender struct {
Expand Down
Loading
Loading