only table in clients page & better load and save

This commit is contained in:
Alireza Ahmadi
2025-01-18 10:28:04 +01:00
parent 67582015d3
commit f18345b30d
14 changed files with 91 additions and 259 deletions
+2 -2
View File
@@ -258,11 +258,11 @@ func (a *APIHandler) loadData(c *gin.Context) (interface{}, error) {
func (a *APIHandler) loadPartialData(c *gin.Context, objs []string) error {
data := make(map[string]interface{}, 0)
id := c.Query("id")
for _, obj := range objs {
switch obj {
case "inbounds":
id := c.Query("id")
inbounds, err := a.InboundService.Get(id)
if err != nil {
return err
@@ -287,7 +287,7 @@ func (a *APIHandler) loadPartialData(c *gin.Context, objs []string) error {
}
data[obj] = tlsConfigs
case "clients":
clients, err := a.ClientService.GetAll()
clients, err := a.ClientService.Get(id)
if err != nil {
return err
}
+2 -2
View File
@@ -26,9 +26,9 @@ type Client struct {
Id uint `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
Enable bool `json:"enable" form:"enable"`
Name string `json:"name" form:"name"`
Config json.RawMessage `json:"config" form:"config"`
Config json.RawMessage `json:"config,omitempty" form:"config"`
Inbounds json.RawMessage `json:"inbounds" form:"inbounds"`
Links json.RawMessage `json:"links" form:"links"`
Links json.RawMessage `json:"links,omitempty" form:"links"`
Volume int64 `json:"volume" form:"volume"`
Expiry int64 `json:"expiry" form:"expiry"`
Down int64 `json:"down" form:"down"`
+22 -4
View File
@@ -16,14 +16,32 @@ type ClientService struct {
InboundService
}
func (s *ClientService) GetAll() ([]model.Client, error) {
func (s *ClientService) Get(id string) (*[]model.Client, error) {
if id == "" {
return s.GetAll()
}
return s.getById(id)
}
func (s *ClientService) getById(id string) (*[]model.Client, error) {
db := database.GetDB()
clients := []model.Client{}
err := db.Model(model.Client{}).Scan(&clients).Error
var client []model.Client
err := db.Model(model.Client{}).Where("id in ?", strings.Split(id, ",")).Scan(&client).Error
if err != nil {
return nil, err
}
return clients, nil
return &client, nil
}
func (s *ClientService) GetAll() (*[]model.Client, error) {
db := database.GetDB()
var clients []model.Client
err := db.Model(model.Client{}).Select("`id`, `enable`, `name`, `desc`, `group`, `inbounds`, `up`, `down`, `volume`, `expiry`").Scan(&clients).Error
if err != nil {
return nil, err
}
return &clients, nil
}
func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, hostname string) ([]uint, error) {
+2
View File
@@ -120,6 +120,7 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, login
var err error
var inboundIds []uint
var inboundId uint
var objs []string = []string{obj}
db := database.GetDB()
tx := db.Begin()
@@ -134,6 +135,7 @@ func (s *ConfigService) Save(obj string, act string, data json.RawMessage, login
switch obj {
case "clients":
inboundIds, err = s.ClientService.Save(tx, act, data, hostname)
objs = append(objs, "inbounds")
case "tls":
inboundIds, err = s.TlsService.Save(tx, act, data)
case "inbounds":
-2
View File
@@ -244,9 +244,7 @@ func hysteria2Link(
if downmbps, ok := inbound["down_mbps"].(string); ok {
params["down_mbps"] = downmbps
}
fmt.Printf("%+v\n", addr["tls"])
if tls, ok := addr["tls"].(map[string]interface{}); ok {
fmt.Printf("%+v\n", tls)
if sni, ok := tls["server_name"].(string); ok {
params["sni"] = sni
}