From bf8f001a30db24bf17b9f1a8ae0edce6482558d6 Mon Sep 17 00:00:00 2001 From: luorijun Date: Mon, 22 Dec 2025 17:31:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=A3=E7=90=86=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/handlers/proxy.go | 76 ++++++++++++++++++++++++++++++------------- web/routes.go | 3 +- web/services/proxy.go | 4 +-- 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/web/handlers/proxy.go b/web/handlers/proxy.go index 95dda48..aaa921e 100644 --- a/web/handlers/proxy.go +++ b/web/handlers/proxy.go @@ -3,7 +3,9 @@ package handlers import ( "net/netip" "platform/pkg/env" + "platform/web/auth" "platform/web/core" + "platform/web/globals" s "platform/web/services" "time" @@ -23,20 +25,40 @@ func DebugRegisterProxyBaiYin(c *fiber.Ctx) error { return nil } +// 注册白银代理网关 +func ProxyRegisterBaiYin(c *fiber.Ctx) error { + _, err := auth.GetAuthCtx(c).PermitOfficialClient() + if err != nil { + return err + } + + req := new(RegisterProxyBaiyinReq) + err = globals.Validator.ParseBody(c, req) + if err != nil { + return err + } + + addr, err := netip.ParseAddr(req.IP) + if err != nil { + return core.NewServErr("IP地址格式错误", err) + } + + err = s.Proxy.RegisterBaiyin(req.Name, addr, req.Username, req.Password) + if err != nil { + return core.NewServErr("注册失败", err) + } + + return nil +} + +type RegisterProxyBaiyinReq struct { + Name string `json:"name" validate:"required"` + IP string `json:"ip" validate:"required"` + Username string `json:"username" validate:"required"` + Password string `json:"password" validate:"required"` +} + // region 报告上线 - -type ProxyReportOnlineReq struct { - Name string `json:"name" validate:"required"` - Version int `json:"version" validate:"required"` -} - -type ProxyReportOnlineResp struct { - Id int32 `json:"id"` - Secret string `json:"secret"` - Permits []*ProxyPermit `json:"permits"` - Edges []*ProxyEdge `json:"edges"` -} - func ProxyReportOnline(c *fiber.Ctx) (err error) { return c.JSON(map[string]any{ "error": "接口暂不可用", @@ -140,12 +162,19 @@ func ProxyReportOnline(c *fiber.Ctx) (err error) { // }) } -// region 报告下线 - -type ProxyReportOfflineReq struct { - Id int32 `json:"id" validate:"required"` +type ProxyReportOnlineReq struct { + Name string `json:"name" validate:"required"` + Version int `json:"version" validate:"required"` } +type ProxyReportOnlineResp struct { + Id int32 `json:"id"` + Secret string `json:"secret"` + Permits []*ProxyPermit `json:"permits"` + Edges []*ProxyEdge `json:"edges"` +} + +// region 报告下线 func ProxyReportOffline(c *fiber.Ctx) (err error) { return c.JSON(map[string]any{ "error": "接口暂不可用", @@ -183,13 +212,11 @@ func ProxyReportOffline(c *fiber.Ctx) (err error) { // return nil } -// region 报告更新 - -type ProxyReportUpdateReq struct { - Id int32 `json:"id" validate:"required"` - Edges []*ProxyEdge `json:"edges" validate:"required"` +type ProxyReportOfflineReq struct { + Id int32 `json:"id" validate:"required"` } +// region 报告更新 func ProxyReportUpdate(c *fiber.Ctx) (err error) { return c.JSON(map[string]any{ "error": "接口暂不可用", @@ -348,6 +375,11 @@ func ProxyReportUpdate(c *fiber.Ctx) (err error) { // return nil } +type ProxyReportUpdateReq struct { + Id int32 `json:"id" validate:"required"` + Edges []*ProxyEdge `json:"edges" validate:"required"` +} + type ProxyPermit struct { Id int32 `json:"id"` Expire time.Time `json:"expire"` diff --git a/web/routes.go b/web/routes.go index d1204a6..33271bc 100644 --- a/web/routes.go +++ b/web/routes.go @@ -72,13 +72,14 @@ func ApplyRouters(app *fiber.App) { proxy.Post("/online", handlers.ProxyReportOnline) proxy.Post("/offline", handlers.ProxyReportOffline) proxy.Post("/update", handlers.ProxyReportUpdate) + proxy.Post("/register", handlers.ProxyRegisterBaiYin) // 节点 edge := api.Group("/edge") edge.Post("/assign", handlers.AssignEdge) edge.Post("/all", handlers.AllEdgesAvailable) - // 其他系统接口 + // 前台 inquiry := api.Group("/inquiry") inquiry.Post("/create", handlers.CreateInquiry) diff --git a/web/services/proxy.go b/web/services/proxy.go index de60d5c..14515be 100644 --- a/web/services/proxy.go +++ b/web/services/proxy.go @@ -31,12 +31,12 @@ func (s *proxyService) AllProxies(proxyType m.ProxyType, channels bool) ([]*m.Pr } // RegisterBaiyin 注册新代理服务 -func (s *proxyService) RegisterBaiyin(Mac string, IP netip.Addr, username, password string) error { +func (s *proxyService) RegisterBaiyin(Name string, IP netip.Addr, username, password string) error { // 保存代理信息 proxy := &m.Proxy{ Version: 0, - Mac: Mac, + Mac: Name, IP: orm.Inet{Addr: IP}, Secret: u.P(fmt.Sprintf("%s:%s", username, password)), Type: m.ProxyTypeBaiYin,