文件名参数处理
This commit is contained in:
parent
6136a98588
commit
c4d3792edf
|
|
@ -3,7 +3,10 @@ package config
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/flytam/filenamify"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"log"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -59,8 +62,8 @@ func (s System) GetJob(name string) (Job, error) {
|
||||||
func (j Job) GetFileName(params map[string]interface{}) string {
|
func (j Job) GetFileName(params map[string]interface{}) string {
|
||||||
|
|
||||||
m := regexp.MustCompile("({[a-zA-Z0-9]+})")
|
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])
|
field := string(b[1 : len(b)-1])
|
||||||
|
|
||||||
if val, ok := params[field]; ok {
|
if val, ok := params[field]; ok {
|
||||||
|
|
@ -69,7 +72,13 @@ func (j Job) GetFileName(params map[string]interface{}) string {
|
||||||
return b
|
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 {
|
func (t Task) GetSql(params map[string]interface{}) string {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue