mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-08 08:36:37 +08:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -63,7 +63,6 @@ type NodeView struct {
|
||||
Name string `json:"name"`
|
||||
IP string `json:"ip"`
|
||||
AgentToken string `json:"agent_token"`
|
||||
Pending bool `json:"pending"`
|
||||
AutoUpdateEnabled bool `json:"auto_update_enabled"`
|
||||
UpdateRequested bool `json:"update_requested"`
|
||||
AgentVersion string `json:"agent_version"`
|
||||
|
||||
@@ -137,6 +137,21 @@ func DiffConfigVersion() (*ConfigDiffResult, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func HasConfigChanges() (bool, error) {
|
||||
bundle, err := buildCurrentConfigBundle(false)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
activeVersion, err := model.GetActiveConfigVersion()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return len(bundle.Routes) > 0, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return activeVersion.Checksum != bundle.Checksum, nil
|
||||
}
|
||||
|
||||
func PublishConfigVersion(createdBy string) (*ReleaseResult, error) {
|
||||
bundle, err := buildCurrentConfigBundle(true)
|
||||
if err != nil {
|
||||
@@ -145,6 +160,13 @@ func PublishConfigVersion(createdBy string) (*ReleaseResult, error) {
|
||||
if len(bundle.Routes) == 0 {
|
||||
return nil, errors.New("没有可发布的启用规则")
|
||||
}
|
||||
activeVersion, err := model.GetActiveConfigVersion()
|
||||
if err == nil && activeVersion.Checksum == bundle.Checksum {
|
||||
return nil, errors.New("当前规则没有变更,不能重复发布")
|
||||
}
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
supportFilesJSON, err := json.Marshal(bundle.SupportFiles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -178,7 +178,6 @@ func buildNodeView(node *model.Node) *NodeView {
|
||||
LastError: node.LastError,
|
||||
CreatedAt: node.CreatedAt,
|
||||
UpdatedAt: node.UpdatedAt,
|
||||
Pending: status == NodeStatusPending,
|
||||
AutoUpdateEnabled: node.AutoUpdateEnabled,
|
||||
UpdateRequested: node.UpdateRequested,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user