mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-19 00:18:19 +08:00
feat: not inline rule-provider can also set payload
as fallback rules when file/http parsing fails
This commit is contained in:
parent
61d6a9abd6
commit
5c40a6340c
@ -63,5 +63,5 @@ func ParseRuleProvider(name string, mapping map[string]any, parse common.ParseRu
|
||||
return nil, fmt.Errorf("unsupported vehicle type: %s", schema.Type)
|
||||
}
|
||||
|
||||
return NewRuleSetProvider(name, behavior, format, time.Duration(uint(schema.Interval))*time.Second, vehicle, parse), nil
|
||||
return NewRuleSetProvider(name, behavior, format, time.Duration(uint(schema.Interval))*time.Second, vehicle, schema.Payload, parse), nil
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func (rp *RuleSetProvider) Close() error {
|
||||
return rp.ruleSetProvider.Close()
|
||||
}
|
||||
|
||||
func NewRuleSetProvider(name string, behavior P.RuleBehavior, format P.RuleFormat, interval time.Duration, vehicle P.Vehicle, parse common.ParseRuleFunc) P.RuleProvider {
|
||||
func NewRuleSetProvider(name string, behavior P.RuleBehavior, format P.RuleFormat, interval time.Duration, vehicle P.Vehicle, payload []string, parse common.ParseRuleFunc) P.RuleProvider {
|
||||
rp := &ruleSetProvider{
|
||||
baseProvider: baseProvider{
|
||||
behavior: behavior,
|
||||
@ -147,6 +147,9 @@ func NewRuleSetProvider(name string, behavior P.RuleBehavior, format P.RuleForma
|
||||
}
|
||||
|
||||
rp.strategy = newStrategy(behavior, parse)
|
||||
if len(payload) > 0 { // using as fallback rules
|
||||
rp.strategy = rulesParseInline(payload, rp.strategy)
|
||||
}
|
||||
rp.Fetcher = resource.NewFetcher(name, interval, vehicle, func(bytes []byte) (ruleStrategy, error) {
|
||||
return rulesParse(bytes, newStrategy(behavior, parse), format)
|
||||
}, onUpdate)
|
||||
|
Loading…
Reference in New Issue
Block a user