Update common.go

pull/3116/head
Darren Yu 10 months ago committed by GitHub
parent ab0a6bf30c
commit 29bfe4bb74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"math/rand" "math/rand"
"path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv" "strconv"
@ -101,7 +102,7 @@ func Replace(table map[string]string, s string) string {
// ReplaceMagicVar 动态替换字符串中的魔法变量 // ReplaceMagicVar 动态替换字符串中的魔法变量
func ReplaceMagicVar(rawString string, fsSeparator string, pathAvailable bool, blobAvailable bool, func ReplaceMagicVar(rawString string, fsSeparator string, pathAvailable bool, blobAvailable bool,
timeConst time.Time, userId int, originName string, originPath string, completeBlobPath string) string { timeConst time.Time, userId int, originName string, originPath string, completeBlobPath string) string {
re := regexp.MustCompile(`\{[^{}]+\}`) re := regexp.MustCompile(`\{[^{}]+\}`)
return re.ReplaceAllStringFunc(rawString, func(match string) string { return re.ReplaceAllStringFunc(rawString, func(match string) string {
switch match { switch match {
@ -164,11 +165,7 @@ func ReplaceMagicVar(rawString string, fsSeparator string, pathAvailable bool, b
return match return match
case "{blob_path}": case "{blob_path}":
if blobAvailable { if blobAvailable {
lastSlash := strings.LastIndexAny(completeBlobPath, "/\\") return path.Dir(completeBlobPath) + fsSeparator
if lastSlash >= 0 {
return completeBlobPath[:lastSlash] + fsSeparator
}
return fsSeparator
} }
return match return match
default: default:

Loading…
Cancel
Save