option warp endpoint #345

This commit is contained in:
Alireza Ahmadi
2025-01-19 01:52:25 +01:00
parent 4dc02f783a
commit a0dc165995
8 changed files with 425 additions and 6 deletions
+23 -1
View File
@@ -10,7 +10,9 @@ import (
"gorm.io/gorm"
)
type EndpointService struct{}
type EndpointService struct {
WarpService
}
func (o *EndpointService) GetAll() (*[]map[string]interface{}, error) {
db := database.GetDB()
@@ -25,6 +27,7 @@ func (o *EndpointService) GetAll() (*[]map[string]interface{}, error) {
"id": endpoint.Id,
"type": endpoint.Type,
"tag": endpoint.Tag,
"ext": endpoint.Ext,
}
if endpoint.Options != nil {
var restFields map[string]json.RawMessage
@@ -68,6 +71,25 @@ func (s *EndpointService) Save(tx *gorm.DB, act string, data json.RawMessage) er
return err
}
if endpoint.Type == "warp" {
if act == "new" {
err = s.WarpService.RegisterWarp(&endpoint)
if err != nil {
return err
}
} else {
var old_license string
err = tx.Model(model.Endpoint{}).Select("json_extract(ext, '$.license_key')").Where("id = ?", endpoint.Id).Find(&old_license).Error
if err != nil {
return err
}
err = s.WarpService.SetWarpLicense(old_license, &endpoint)
if err != nil {
return err
}
}
}
if corePtr.IsRunning() {
configData, err := endpoint.MarshalJSON()
if err != nil {