Feat: {path} marker in name rule representing the virtual path of the file

This commit is contained in:
HFO4
2019-11-19 16:42:36 +08:00
parent 2e9f256462
commit 88a543ef74
8 changed files with 71 additions and 33 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/HFO4/cloudreve/pkg/util"
"github.com/jinzhu/gorm"
"path/filepath"
"strconv"
"time"
)
@ -69,7 +70,7 @@ func (policy *Policy) SerializeOptions() (err error) {
}
// GeneratePath 生成存储文件的路径
func (policy *Policy) GeneratePath(uid uint) string {
func (policy *Policy) GeneratePath(uid uint, path string) string {
dirRule := policy.DirNameRule
replaceTable := map[string]string{
"{randomkey16}": util.RandStringRunes(16),
@ -78,9 +79,10 @@ func (policy *Policy) GeneratePath(uid uint) string {
"{uid}": strconv.Itoa(int(uid)),
"{datetime}": time.Now().Format("20060102150405"),
"{date}": time.Now().Format("20060102"),
"{path}": path + "/",
}
dirRule = util.Replace(replaceTable, dirRule)
return dirRule
return filepath.Clean(dirRule)
}
// GenerateFileName 生成存储文件名