新增提取函数,实现通过套餐编号提取
This commit is contained in:
@@ -102,13 +102,17 @@ func CreateChannel(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
// 创建通道
|
||||
no, err := s.FindResourceNoById(req.ResourceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var isp *m.EdgeISP
|
||||
if req.Isp != nil {
|
||||
isp = u.X(m.ToEdgeISP(*req.Isp))
|
||||
}
|
||||
result, err := s.Channel.CreateChannels(
|
||||
ip,
|
||||
req.ResourceId,
|
||||
ip, no,
|
||||
req.AuthType == s.ChannelAuthTypeIp,
|
||||
req.AuthType == s.ChannelAuthTypePass,
|
||||
req.Count,
|
||||
@@ -149,6 +153,69 @@ type CreateChannelReq struct {
|
||||
Isp *int `json:"isp"`
|
||||
}
|
||||
|
||||
// CreateChannelV2 创建新通道 v2,使用 resource_no 替代 resource_id
|
||||
func CreateChannelV2(c *fiber.Ctx) error {
|
||||
// 不检查权限,允许 api 调用
|
||||
|
||||
// 解析参数
|
||||
req := new(CreateChannelReqV2)
|
||||
if err := g.Validator.ParseBody(c, req); err != nil {
|
||||
return core.NewBizErr("解析参数失败", err)
|
||||
}
|
||||
|
||||
ip, err := netip.ParseAddr(c.IP())
|
||||
if err != nil {
|
||||
return core.NewBizErr("获取客户端地址失败", err)
|
||||
}
|
||||
|
||||
// 创建通道
|
||||
var isp *m.EdgeISP
|
||||
if req.Isp != nil {
|
||||
isp = u.X(m.ToEdgeISP(*req.Isp))
|
||||
}
|
||||
result, err := s.Channel.CreateChannels(
|
||||
ip,
|
||||
req.ResourceNo,
|
||||
req.AuthType == s.ChannelAuthTypeIp,
|
||||
req.AuthType == s.ChannelAuthTypePass,
|
||||
req.Count,
|
||||
&s.EdgeFilter{
|
||||
Isp: isp,
|
||||
Prov: req.Prov,
|
||||
City: req.City,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
var resp = make([]*CreateChannelRespItem, len(result))
|
||||
for i, channel := range result {
|
||||
resp[i] = &CreateChannelRespItem{
|
||||
Proto: req.Protocol,
|
||||
Host: channel.Host,
|
||||
IP: channel.Proxy.IP.String(),
|
||||
Port: channel.Port,
|
||||
}
|
||||
if req.AuthType == s.ChannelAuthTypePass {
|
||||
resp[i].Username = channel.Username
|
||||
resp[i].Password = channel.Password
|
||||
}
|
||||
}
|
||||
return c.JSON(resp)
|
||||
}
|
||||
|
||||
type CreateChannelReqV2 struct {
|
||||
ResourceNo string `json:"resource_no" validate:"required"`
|
||||
AuthType s.ChannelAuthType `json:"auth_type" validate:"required"`
|
||||
Protocol int `json:"protocol" validate:"required"`
|
||||
Count int `json:"count" validate:"required"`
|
||||
Prov *string `json:"prov"`
|
||||
City *string `json:"city"`
|
||||
Isp *int `json:"isp"`
|
||||
}
|
||||
|
||||
type CreateChannelRespItem struct {
|
||||
Proto int `json:"-"`
|
||||
Host string `json:"host"`
|
||||
|
||||
Reference in New Issue
Block a user