优化数据库结构与数据插入逻辑

This commit is contained in:
2025-04-12 18:03:44 +08:00
parent 438a55cc3e
commit 8c268fd7a9
28 changed files with 218 additions and 213 deletions

View File

@@ -12,7 +12,7 @@ import (
"platform/pkg/orm"
"platform/pkg/rds"
"platform/pkg/remote"
"platform/pkg/v"
"platform/pkg/u"
"platform/web/common"
"platform/web/models"
q "platform/web/queries"
@@ -37,12 +37,12 @@ const (
ChannelAuthTypePass
)
type ChannelProtocol string
type ChannelProtocol int32
const (
ProtocolSocks5 = ChannelProtocol("socks5")
ProtocolHTTP = ChannelProtocol("http")
ProtocolHttps = ChannelProtocol("https")
ProtocolHTTP = ChannelProtocol(1)
ProtocolHttps = ChannelProtocol(2)
ProtocolSocks5 = ChannelProtocol(3)
)
type ResourceInfo struct {
@@ -142,7 +142,7 @@ func (s *channelService) RemoveChannels(ctx context.Context, auth *AuthContext,
Port: int(channel.ProxyPort),
Edge: &[]string{},
AutoEdgeConfig: &remote.AutoEdgeConfig{
Count: v.P(0),
Count: u.P(0),
},
Status: false,
}
@@ -600,7 +600,7 @@ func assignPort(
Province: filter.Prov,
City: filter.City,
Isp: filter.Isp,
Count: v.P(1),
Count: u.P(1),
PacketLoss: 30,
},
})
@@ -608,7 +608,7 @@ func assignPort(
switch authType {
case ChannelAuthTypeIp:
configs[i].Whitelist = &whitelist
configs[i].Userpass = v.P("")
configs[i].Userpass = u.P("")
for _, item := range whitelist {
channels = append(channels, &models.Channel{
UserID: userId,
@@ -617,19 +617,19 @@ func assignPort(
ProxyPort: int32(port),
AuthIP: true,
AuthPass: false,
Protocol: string(protocol),
Protocol: int32(protocol),
Expiration: expiration,
})
}
result = append(result, &PortInfo{
Proto: string(protocol),
Proto: protocol,
Host: proxy.Host,
Port: port,
})
case ChannelAuthTypePass:
username, password := genPassPair()
configs[i].Whitelist = &[]string{}
configs[i].Userpass = v.P(fmt.Sprintf("%s:%s", username, password))
configs[i].Userpass = u.P(fmt.Sprintf("%s:%s", username, password))
channels = append(channels, &models.Channel{
UserID: userId,
ProxyID: proxy.ID,
@@ -638,11 +638,11 @@ func assignPort(
AuthPass: true,
Username: username,
Password: password,
Protocol: string(protocol),
Protocol: int32(protocol),
Expiration: expiration,
})
result = append(result, &PortInfo{
Proto: string(protocol),
Proto: protocol,
Host: proxy.Host,
Port: port,
Username: &username,
@@ -694,16 +694,17 @@ func assignPort(
}
type PortInfo struct {
Proto string `json:"-"`
Host string `json:"host"`
Port int `json:"port"`
Username *string `json:"username,omitempty"`
Password *string `json:"password,omitempty"`
Proto ChannelProtocol `json:"-"`
Host string `json:"host"`
Port int `json:"port"`
Username *string `json:"username,omitempty"`
Password *string `json:"password,omitempty"`
}
// endregion
func genPassPair() (string, string) {
//goland:noinspection SpellCheckingInspection
var alphabet = []rune("abcdefghjkmnpqrstuvwxyz")
var numbers = []rune("23456789")