From 71013d5b0de716dbbb176f464152b9c5a07007f8 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 27 Apr 2025 14:22:14 +0200 Subject: [PATCH] add Substrings parameter to cfgset --- src/models/cfg.go | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/models/cfg.go b/src/models/cfg.go index 2220e4f..7cbc3de 100644 --- a/src/models/cfg.go +++ b/src/models/cfg.go @@ -71,6 +71,18 @@ func (cfgset *CfgSet) BuildRegex(cfg *config.Config) { cfgset.Regex = fmt.Sprintf("(%s)", strings.Join(regs, "|")) } +func (cfgset *CfgSet) BuildSubStrings(cfg *config.Config) { + var rr []CfgExpr + err := cfg.Db.Where("cfgset_id = $1 AND enabled", cfgset.ID).OrderBy("expr").Find(&rr) + if err != nil { + fmt.Println(err) + } + cfgset.SubStrings = []string{} + for _, v := range rr { + cfgset.SubStrings = append(cfgset.SubStrings, v.Expr) + } +} + func GetSets(cfg *config.Config) (res []CfgSet, err error) { var w = []CfgSet{} @@ -101,8 +113,9 @@ func GetAllConfigv2(cfg *config.Config) (res CfgAllv2, err error) { var sets = []CfgSet{} if err := cfg.Db.Find(&sets); err == nil { - for i, _ := range sets { + for i := range sets { sets[i].BuildRegex(cfg) + sets[i].BuildSubStrings(cfg) } res.Sets = sets } @@ -178,14 +191,15 @@ type Cfg struct { } type CfgSet struct { - ID int `xorm:"pk autoincr" json:"-"` - Path string `xorm:"text notnull default" json:"path"` - Src string `xorm:"text notnull" json:"src"` - Filename string `xorm:"text notnull" json:"filename"` - Regex string `xorm:"-" json:"regex"` - Blocktime int64 `xorm:"notnull default 60" json:"blocktime"` - TryFail int64 `xorm:"notnull default 5" json:"tryfail"` - Enabled bool `xorm:"notnull default true" json:"-"` + ID int `xorm:"pk autoincr" json:"-"` + Path string `xorm:"text notnull default" json:"path"` + Src string `xorm:"text notnull" json:"src"` + Filename string `xorm:"text notnull" json:"filename"` + Regex string `xorm:"-" json:"regex"` + SubStrings []string `xorm:"-" json:"substrings"` + Blocktime int64 `xorm:"notnull default 60" json:"blocktime"` + TryFail int64 `xorm:"notnull default 5" json:"tryfail"` + Enabled bool `xorm:"notnull default true" json:"-"` } type CfgExpr struct {