Finish config mapping
This commit is contained in:
@@ -12,6 +12,7 @@ func loadV1Config(content []byte) (*ZurgConfigV1, error) {
|
||||
if err := yaml.Unmarshal(content, &configV1); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &configV1, nil
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ func (z *ZurgConfigV1) matchFilter(fileID, torrentName string, filter *FilterCon
|
||||
return true
|
||||
}
|
||||
if filter.RegexStr != "" {
|
||||
regex := regexp.MustCompile(filter.RegexStr)
|
||||
regex := compilePattern(filter.RegexStr)
|
||||
if regex.MatchString(torrentName) {
|
||||
return true
|
||||
}
|
||||
@@ -88,3 +89,39 @@ func (z *ZurgConfigV1) matchFilter(fileID, torrentName string, filter *FilterCon
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func compilePattern(pattern string) *regexp.Regexp {
|
||||
flags := map[rune]string{
|
||||
'i': "(?i)",
|
||||
'm': "(?m)",
|
||||
's': "(?s)",
|
||||
'x': "(?x)",
|
||||
}
|
||||
|
||||
lastSlash := strings.LastIndex(pattern, "/")
|
||||
secondLastSlash := strings.LastIndex(pattern[:lastSlash], "/")
|
||||
|
||||
// Extract the core pattern
|
||||
corePattern := pattern[secondLastSlash+1 : lastSlash]
|
||||
|
||||
// Extract and process flags
|
||||
flagSection := pattern[lastSlash+1:]
|
||||
flagString := ""
|
||||
processedFlags := make(map[rune]bool)
|
||||
for _, flag := range flagSection {
|
||||
if replacement, ok := flags[flag]; ok && !processedFlags[flag] {
|
||||
flagString += replacement
|
||||
processedFlags[flag] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Combine the processed flags with the core pattern
|
||||
finalPattern := flagString + corePattern
|
||||
|
||||
// Validate pattern
|
||||
if finalPattern == "" || finalPattern == flagString {
|
||||
return nil
|
||||
}
|
||||
|
||||
return regexp.MustCompile(finalPattern)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package config
|
||||
type ZurgConfigV1 struct {
|
||||
ZurgConfig
|
||||
Directories map[string]*DirectoryFilterConditionsV1 `yaml:"directories"`
|
||||
Duplicates bool `yaml:"duplicates"`
|
||||
}
|
||||
type DirectoryFilterConditionsV1 struct {
|
||||
Group string `yaml:"group"`
|
||||
|
||||
Reference in New Issue
Block a user