提供一个测试注册代理接口

This commit is contained in:
2025-12-01 12:42:51 +08:00
parent c0b3490d00
commit 299ce821d5
5 changed files with 86 additions and 15 deletions

View File

@@ -1,6 +1,11 @@
package services
import (
"fmt"
"net/netip"
"platform/pkg/u"
"platform/web/core"
"platform/web/globals/orm"
m "platform/web/models"
q "platform/web/queries"
"time"
@@ -10,6 +15,7 @@ var Proxy = &proxyService{}
type proxyService struct{}
// AllProxies 获取所有代理
func (s *proxyService) AllProxies(proxyType m.ProxyType, channels bool) ([]*m.Proxy, error) {
proxies, err := q.Proxy.Where(
q.Proxy.Type.Eq(int(proxyType)),
@@ -23,3 +29,36 @@ func (s *proxyService) AllProxies(proxyType m.ProxyType, channels bool) ([]*m.Pr
return proxies, nil
}
// RegisterBaiyin 注册新代理服务
func (s *proxyService) RegisterBaiyin(Mac string, IP netip.Addr, username, password string) error {
// 添加可用通道到 redis
chans := make([]netip.AddrPort, 10000)
for i := range 10000 {
chans[i] = netip.AddrPortFrom(IP, uint16(i+10000))
}
err := registerChans(chans)
if err != nil {
return core.NewServErr("添加通道失败")
}
// 保存代理信息
if err := q.Proxy.Create(&m.Proxy{
Version: 0,
Mac: Mac,
IP: orm.Inet{Addr: IP},
Secret: u.P(fmt.Sprintf("%s:%s", username, password)),
Type: m.ProxyTypeBaiYin,
Status: m.ProxyStatusOnline,
}); err != nil {
return core.NewServErr("保存通道数据失败")
}
return nil
}
// UnregisterBaiyin 注销代理服务
func (s *proxyService) UnregisterBaiyin(id int) error {
return nil
}