From 6f5caefb00034f7a674113fb978cff277b5b5261 Mon Sep 17 00:00:00 2001 From: haimu0427 Date: Thu, 12 Mar 2026 15:15:01 +0800 Subject: [PATCH] feat(web): add Clash settings to entity and service - Add SubClashEnable, SubClashPath, SubClashURI fields - Add getter methods for Clash configuration - Set default Clash path to /clash/ and enable by default Co-Authored-By: Claude Sonnet 4.6 --- web/entity/entity.go | 10 ++++++++++ web/service/setting.go | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/web/entity/entity.go b/web/entity/entity.go index 40294925..14353cf0 100644 --- a/web/entity/entity.go +++ b/web/entity/entity.go @@ -76,6 +76,9 @@ type AllSetting struct { SubURI string `json:"subURI" form:"subURI"` // Subscription server URI SubJsonPath string `json:"subJsonPath" form:"subJsonPath"` // Path for JSON subscription endpoint SubJsonURI string `json:"subJsonURI" form:"subJsonURI"` // JSON subscription server URI + SubClashEnable bool `json:"subClashEnable" form:"subClashEnable"` // Enable Clash/Mihomo subscription endpoint + SubClashPath string `json:"subClashPath" form:"subClashPath"` // Path for Clash/Mihomo subscription endpoint + SubClashURI string `json:"subClashURI" form:"subClashURI"` // Clash/Mihomo subscription server URI SubJsonFragment string `json:"subJsonFragment" form:"subJsonFragment"` // JSON subscription fragment configuration SubJsonNoises string `json:"subJsonNoises" form:"subJsonNoises"` // JSON subscription noise configuration SubJsonMux string `json:"subJsonMux" form:"subJsonMux"` // JSON subscription mux configuration @@ -168,6 +171,13 @@ func (s *AllSetting) CheckValid() error { s.SubJsonPath += "/" } + if !strings.HasPrefix(s.SubClashPath, "/") { + s.SubClashPath = "/" + s.SubClashPath + } + if !strings.HasSuffix(s.SubClashPath, "/") { + s.SubClashPath += "/" + } + _, err := time.LoadLocation(s.TimeLocation) if err != nil { return common.NewError("time location not exist:", s.TimeLocation) diff --git a/web/service/setting.go b/web/service/setting.go index 5c93e9fd..7027d466 100644 --- a/web/service/setting.go +++ b/web/service/setting.go @@ -71,6 +71,9 @@ var defaultValueMap = map[string]string{ "subURI": "", "subJsonPath": "/json/", "subJsonURI": "", + "subClashEnable": "true", + "subClashPath": "/clash/", + "subClashURI": "", "subJsonFragment": "", "subJsonNoises": "", "subJsonMux": "", @@ -555,6 +558,18 @@ func (s *SettingService) GetSubJsonURI() (string, error) { return s.getString("subJsonURI") } +func (s *SettingService) GetSubClashEnable() (bool, error) { + return s.getBool("subClashEnable") +} + +func (s *SettingService) GetSubClashPath() (string, error) { + return s.getString("subClashPath") +} + +func (s *SettingService) GetSubClashURI() (string, error) { + return s.getString("subClashURI") +} + func (s *SettingService) GetSubJsonFragment() (string, error) { return s.getString("subJsonFragment") } @@ -750,11 +765,13 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) { "defaultKey": func() (any, error) { return s.GetKeyFile() }, "tgBotEnable": func() (any, error) { return s.GetTgbotEnabled() }, "subEnable": func() (any, error) { return s.GetSubEnable() }, - "subJsonEnable": func() (any, error) { return s.GetSubJsonEnable() }, - "subTitle": func() (any, error) { return s.GetSubTitle() }, - "subURI": func() (any, error) { return s.GetSubURI() }, - "subJsonURI": func() (any, error) { return s.GetSubJsonURI() }, - "remarkModel": func() (any, error) { return s.GetRemarkModel() }, + "subJsonEnable": func() (any, error) { return s.GetSubJsonEnable() }, + "subClashEnable": func() (any, error) { return s.GetSubClashEnable() }, + "subTitle": func() (any, error) { return s.GetSubTitle() }, + "subURI": func() (any, error) { return s.GetSubURI() }, + "subJsonURI": func() (any, error) { return s.GetSubJsonURI() }, + "subClashURI": func() (any, error) { return s.GetSubClashURI() }, + "remarkModel": func() (any, error) { return s.GetRemarkModel() }, "datepicker": func() (any, error) { return s.GetDatepicker() }, "ipLimitEnable": func() (any, error) { return s.GetIpLimitEnable() }, } @@ -776,12 +793,19 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) { subJsonEnable = b } } - if (subEnable && result["subURI"].(string) == "") || (subJsonEnable && result["subJsonURI"].(string) == "") { + subClashEnable := false + if v, ok := result["subClashEnable"]; ok { + if b, ok2 := v.(bool); ok2 { + subClashEnable = b + } + } + if (subEnable && result["subURI"].(string) == "") || (subJsonEnable && result["subJsonURI"].(string) == "") || (subClashEnable && result["subClashURI"].(string) == "") { subURI := "" subTitle, _ := s.GetSubTitle() subPort, _ := s.GetSubPort() subPath, _ := s.GetSubPath() subJsonPath, _ := s.GetSubJsonPath() + subClashPath, _ := s.GetSubClashPath() subDomain, _ := s.GetSubDomain() subKeyFile, _ := s.GetSubKeyFile() subCertFile, _ := s.GetSubCertFile() @@ -811,6 +835,9 @@ func (s *SettingService) GetDefaultSettings(host string) (any, error) { if subJsonEnable && result["subJsonURI"].(string) == "" { result["subJsonURI"] = subURI + subJsonPath } + if subClashEnable && result["subClashURI"].(string) == "" { + result["subClashURI"] = subURI + subClashPath + } } return result, nil