转发服务注册后提供一个密钥用于安全通信

This commit is contained in:
2025-05-15 15:59:28 +08:00
parent f5396ce9d8
commit 9043dd779b

View File

@@ -1,6 +1,7 @@
package handlers
import (
"crypto/rand"
"github.com/gofiber/fiber/v2"
"log/slog"
auth2 "platform/web/auth"
@@ -20,7 +21,8 @@ type OnlineProxyReq struct {
}
type OnlineProxyResp struct {
Id int32 `json:"id"`
Id int32 `json:"id"`
Secret string `json:"secret"`
}
func OnlineProxy(c *fiber.Ctx) (err error) {
@@ -41,12 +43,14 @@ func OnlineProxy(c *fiber.Ctx) (err error) {
}
// 创建代理
ip := c.Context().RemoteIP()
var ip = c.Context().RemoteIP()
var secret = rand.Text()
var proxy = &m.Proxy{
Name: req.Name,
Version: int32(req.Version),
Host: ip.String(),
Type: int32(proxy2.TypeSelfHosted),
Host: ip.String(),
Secret: secret,
Status: 1,
}
err = q.Proxy.
@@ -63,7 +67,8 @@ func OnlineProxy(c *fiber.Ctx) (err error) {
slog.Debug("注册转发服务", "ip", ip, "id", proxy.ID)
return c.JSON(&OnlineProxyResp{
Id: proxy.ID,
Id: proxy.ID,
Secret: secret,
})
}