diff --git a/biz/config/config.go b/biz/config/config.go index fe345f0..d330775 100644 --- a/biz/config/config.go +++ b/biz/config/config.go @@ -3,7 +3,10 @@ package config import ( "errors" "fmt" + "github.com/flytam/filenamify" "github.com/spf13/viper" + "log" + "path/filepath" "regexp" "strconv" "strings" @@ -59,8 +62,8 @@ func (s System) GetJob(name string) (Job, error) { func (j Job) GetFileName(params map[string]interface{}) string { m := regexp.MustCompile("({[a-zA-Z0-9]+})") - - name := m.ReplaceAllFunc([]byte(j.File), func(b []byte) []byte { + //替换文件名参数 + fileName := m.ReplaceAllFunc([]byte(j.File), func(b []byte) []byte { field := string(b[1 : len(b)-1]) if val, ok := params[field]; ok { @@ -69,7 +72,13 @@ func (j Job) GetFileName(params map[string]interface{}) string { return b }) - return string(name) + //安全命名 + path, name := filepath.Split(string(fileName)) + name, err := filenamify.Filenamify(name, filenamify.Options{Replacement: ""}) + if err != nil { + log.Printf("不安全的文件名:%s", err.Error()) + } + return path + name } func (t Task) GetSql(params map[string]interface{}) string {