重构通道创建逻辑
This commit is contained in:
@@ -97,13 +97,23 @@ type CreateChannelReq struct {
|
||||
Isp string `json:"isp"`
|
||||
}
|
||||
|
||||
type CreateChannelRespItem struct {
|
||||
Proto s.ChannelProtocol `json:"-"`
|
||||
Host string `json:"host"`
|
||||
Port int32 `json:"port"`
|
||||
Username *string `json:"username,omitempty"`
|
||||
Password *string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
func CreateChannel(c *fiber.Ctx) error {
|
||||
|
||||
// 检查权限
|
||||
authContext, err := auth.Protect(c, []auth.PayloadType{auth.PayloadUser}, []string{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 获取用户信息
|
||||
|
||||
// 检查用户其他权限
|
||||
user, err := q.User.
|
||||
Where(q.User.ID.Eq(authContext.Payload.Id)).
|
||||
Take()
|
||||
@@ -140,6 +150,7 @@ func CreateChannel(c *fiber.Ctx) error {
|
||||
isp = "移动"
|
||||
}
|
||||
|
||||
// 创建通道
|
||||
result, err := s.Channel.CreateChannel(
|
||||
c.Context(),
|
||||
authContext,
|
||||
@@ -157,7 +168,20 @@ func CreateChannel(c *fiber.Ctx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(result)
|
||||
// 返回结果
|
||||
var resp = make([]*CreateChannelRespItem, len(result))
|
||||
for i, channel := range result {
|
||||
resp[i] = &CreateChannelRespItem{
|
||||
Proto: req.Protocol,
|
||||
Host: channel.ProxyHost,
|
||||
Port: channel.ProxyPort,
|
||||
}
|
||||
if req.AuthType == s.ChannelAuthTypePass {
|
||||
resp[i].Username = &channel.Username
|
||||
resp[i].Password = &channel.Password
|
||||
}
|
||||
}
|
||||
return c.JSON(resp)
|
||||
}
|
||||
|
||||
type CreateChannelResultType string
|
||||
|
||||
Reference in New Issue
Block a user