mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-04 12:57:31 +00:00
feat: Add GeoAutoUpdate and GeoUpdateInterval to config (#857)
This commit is contained in:
@@ -55,6 +55,8 @@ type General struct {
|
||||
Interface string `json:"interface-name"`
|
||||
RoutingMark int `json:"-"`
|
||||
GeoXUrl GeoXUrl `json:"geox-url"`
|
||||
GeoAutoUpdate bool `json:"geo-auto-update"`
|
||||
GeoUpdateInterval int `json:"geo-update-interval"`
|
||||
GeodataMode bool `json:"geodata-mode"`
|
||||
GeodataLoader string `json:"geodata-loader"`
|
||||
TCPConcurrent bool `json:"tcp-concurrent"`
|
||||
@@ -298,6 +300,8 @@ type RawConfig struct {
|
||||
Interface string `yaml:"interface-name"`
|
||||
RoutingMark int `yaml:"routing-mark"`
|
||||
Tunnels []LC.Tunnel `yaml:"tunnels"`
|
||||
GeoAutoUpdate bool `yaml:"geo-auto-update" json:"geo-auto-update"`
|
||||
GeoUpdateInterval int `yaml:"geo-update-interval" json:"geo-update-interval"`
|
||||
GeodataMode bool `yaml:"geodata-mode" json:"geodata-mode"`
|
||||
GeodataLoader string `yaml:"geodata-loader" json:"geodata-loader"`
|
||||
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
|
||||
@@ -377,22 +381,24 @@ func Parse(buf []byte) (*Config, error) {
|
||||
func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
|
||||
// config with default value
|
||||
rawCfg := &RawConfig{
|
||||
AllowLan: false,
|
||||
BindAddress: "*",
|
||||
IPv6: true,
|
||||
Mode: T.Rule,
|
||||
GeodataMode: C.GeodataMode,
|
||||
GeodataLoader: "memconservative",
|
||||
UnifiedDelay: false,
|
||||
Authentication: []string{},
|
||||
LogLevel: log.INFO,
|
||||
Hosts: map[string]any{},
|
||||
Rule: []string{},
|
||||
Proxy: []map[string]any{},
|
||||
ProxyGroup: []map[string]any{},
|
||||
TCPConcurrent: false,
|
||||
FindProcessMode: P.FindProcessStrict,
|
||||
GlobalUA: "clash.meta",
|
||||
AllowLan: false,
|
||||
BindAddress: "*",
|
||||
IPv6: true,
|
||||
Mode: T.Rule,
|
||||
GeoAutoUpdate: false,
|
||||
GeoUpdateInterval: 24,
|
||||
GeodataMode: C.GeodataMode,
|
||||
GeodataLoader: "memconservative",
|
||||
UnifiedDelay: false,
|
||||
Authentication: []string{},
|
||||
LogLevel: log.INFO,
|
||||
Hosts: map[string]any{},
|
||||
Rule: []string{},
|
||||
Proxy: []map[string]any{},
|
||||
ProxyGroup: []map[string]any{},
|
||||
TCPConcurrent: false,
|
||||
FindProcessMode: P.FindProcessStrict,
|
||||
GlobalUA: "clash.meta",
|
||||
Tun: RawTun{
|
||||
Enable: false,
|
||||
Device: "",
|
||||
@@ -590,6 +596,8 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
|
||||
|
||||
func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||
geodata.SetLoader(cfg.GeodataLoader)
|
||||
C.GeoAutoUpdate = cfg.GeoAutoUpdate
|
||||
C.GeoUpdateInterval = cfg.GeoUpdateInterval
|
||||
C.GeoIpUrl = cfg.GeoXUrl.GeoIp
|
||||
C.GeoSiteUrl = cfg.GeoXUrl.GeoSite
|
||||
C.MmdbUrl = cfg.GeoXUrl.Mmdb
|
||||
@@ -652,6 +660,8 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
|
||||
Interface: cfg.Interface,
|
||||
RoutingMark: cfg.RoutingMark,
|
||||
GeoXUrl: cfg.GeoXUrl,
|
||||
GeoAutoUpdate: cfg.GeoAutoUpdate,
|
||||
GeoUpdateInterval: cfg.GeoUpdateInterval,
|
||||
GeodataMode: cfg.GeodataMode,
|
||||
GeodataLoader: cfg.GeodataLoader,
|
||||
TCPConcurrent: cfg.TCPConcurrent,
|
||||
|
||||
@@ -28,7 +28,7 @@ func UpdateGeoDatabases() error {
|
||||
return fmt.Errorf("invalid GeoIP database file: %s", err)
|
||||
}
|
||||
|
||||
if saveFile(data, C.Path.GeoIP()) != nil {
|
||||
if err = saveFile(data, C.Path.GeoIP()); err != nil {
|
||||
return fmt.Errorf("can't save GeoIP database file: %w", err)
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ func UpdateGeoDatabases() error {
|
||||
return fmt.Errorf("invalid MMDB database file: %s", err)
|
||||
}
|
||||
_ = instance.Close()
|
||||
|
||||
if saveFile(data, C.Path.MMDB()) != nil {
|
||||
if err = saveFile(data, C.Path.MMDB()); err != nil {
|
||||
return fmt.Errorf("can't save MMDB database file: %w", err)
|
||||
}
|
||||
}
|
||||
@@ -58,7 +57,7 @@ func UpdateGeoDatabases() error {
|
||||
return fmt.Errorf("invalid GeoSite database file: %s", err)
|
||||
}
|
||||
|
||||
if saveFile(data, C.Path.GeoSite()) != nil {
|
||||
if err = saveFile(data, C.Path.GeoSite()); err != nil {
|
||||
return fmt.Errorf("can't save GeoSite database file: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func UpdateUI() error {
|
||||
}
|
||||
|
||||
saved := path.Join(C.Path.HomeDir(), "download.zip")
|
||||
if saveFile(data, saved) != nil {
|
||||
if err = saveFile(data, saved); err != nil {
|
||||
return fmt.Errorf("can't save zip file: %w", err)
|
||||
}
|
||||
defer os.Remove(saved)
|
||||
|
||||
Reference in New Issue
Block a user