文件名参数处理
This commit is contained in:
parent
6136a98588
commit
c4d3792edf
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue