提交 2125f03a 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

convert refer path related to current zendata work dir

上级 7b46fb1d
......@@ -38,7 +38,7 @@ func (s *ConfigService) Get(id int) (config model.ZdConfig, dirs []model.Dir) {
func (s *ConfigService) Save(config *model.ZdConfig) (err error) {
config.Folder = serverUtils.DealWithPathSepRight(config.Folder)
config.Path = vari.WorkDir + config.Folder + serverUtils.AddExt(config.FileName, ".yaml")
config.ReferName = service.PathToName(config.Path, constant.ResDirYaml)
config.ReferName = service.PathToName(config.Path, constant.ResDirYaml, constant.ResTypeConfig)
if config.ID == 0 {
err = s.Create(config)
......@@ -139,9 +139,9 @@ func (s *ConfigService) SyncToDB(fi model.ResFile) (err error) {
po.Path = fi.Path
po.Folder = serverUtils.GetRelativePath(po.Path)
if strings.Index(po.Path, constant.ResDirYaml) > -1 {
po.ReferName = service.PathToName(po.Path, constant.ResDirYaml)
po.ReferName = service.PathToName(po.Path, constant.ResDirYaml, constant.ResTypeConfig)
} else {
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers)
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers, constant.ResTypeConfig)
}
po.FileName = fileUtils.GetFileName(po.Path)
po.Yaml = string(content)
......
......@@ -158,7 +158,7 @@ func (s *DefService) SyncToDB(fi model.ResFile) (err error) {
po.Path = fi.Path
po.Folder = serverUtils.GetRelativePath(po.Path)
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers)
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers, po.Type)
po.FileName = fileUtils.GetFileName(po.Path)
po.Yaml = string(content)
......
......@@ -33,7 +33,7 @@ func (s *ExcelService) Get(id int) (excel model.ZdExcel, dirs []model.Dir) {
func (s *ExcelService) Save(excel *model.ZdExcel) (err error) {
excel.Folder = serverUtils.DealWithPathSepRight(excel.Folder)
excel.Path = vari.WorkDir + excel.Folder + serverUtils.AddExt(excel.FileName, ".xlsx")
excel.ReferName = service.PathToName(excel.Path, constant.ResDirData)
excel.ReferName = service.PathToName(excel.Path, constant.ResDirData, constant.ResTypeExcel)
if excel.ID == 0 {
// excel should not be create on webpage
......@@ -99,7 +99,7 @@ func (s *ExcelService) SyncToDB(file model.ResFile) (err error) {
Sheet: file.Title,
Path: file.Path,
Folder: serverUtils.GetRelativePath(file.Path),
ReferName: service.PathToName(file.Path, constant.ResDirData),
ReferName: service.PathToName(file.Path, constant.ResDirData, constant.ResTypeExcel),
FileName: fileUtils.GetFileName(file.Path),
}
s.excelRepo.Create(&excel)
......
......@@ -37,7 +37,7 @@ func (s *InstancesService) Get(id int) (instances model.ZdInstances, dirs []mode
func (s *InstancesService) Save(instances *model.ZdInstances) (err error) {
instances.Folder = serverUtils.DealWithPathSepRight(instances.Folder)
instances.Path = vari.WorkDir + instances.Folder + serverUtils.AddExt(instances.FileName, ".yaml")
instances.ReferName = service.PathToName(instances.Path, constant.ResDirYaml)
instances.ReferName = service.PathToName(instances.Path, constant.ResDirYaml, constant.ResTypeInstances)
if instances.ID == 0 {
err = s.Create(instances)
......@@ -147,9 +147,9 @@ func (s *InstancesService) SyncToDB(file model.ResFile) (err error) {
po.Path = file.Path
po.Folder = serverUtils.GetRelativePath(po.Path)
if strings.Index(po.Path, constant.ResDirYaml) > -1 {
po.ReferName = service.PathToName(po.Path, constant.ResDirYaml)
po.ReferName = service.PathToName(po.Path, constant.ResDirYaml, constant.ResTypeInstances)
} else {
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers)
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers, constant.ResTypeInstances)
}
po.FileName = fileUtils.GetFileName(po.Path)
po.Yaml = string(content)
......
......@@ -36,7 +36,7 @@ func (s *RangesService) Get(id int) (ranges model.ZdRanges, dirs []model.Dir) {
func (s *RangesService) Save(ranges *model.ZdRanges) (err error) {
ranges.Folder = serverUtils.DealWithPathSepRight(ranges.Folder)
ranges.Path = vari.WorkDir + ranges.Folder + serverUtils.AddExt(ranges.FileName, ".yaml")
ranges.ReferName = service.PathToName(ranges.Path, constant.ResDirYaml)
ranges.ReferName = service.PathToName(ranges.Path, constant.ResDirYaml, constant.ResTypeRanges)
if ranges.ID == 0 {
err = s.Create(ranges)
......@@ -111,9 +111,9 @@ func (s *RangesService) SyncToDB(fi model.ResFile) (err error) {
po.Path = fi.Path
po.Folder = serverUtils.GetRelativePath(po.Path)
if strings.Index(po.Path, constant.ResDirYaml) > -1 {
po.ReferName = service.PathToName(po.Path, constant.ResDirYaml)
po.ReferName = service.PathToName(po.Path, constant.ResDirYaml, constant.ResTypeRanges)
} else {
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers)
po.ReferName = service.PathToName(po.Path, constant.ResDirUsers, constant.ResTypeRanges)
}
po.FileName = fileUtils.GetFileName(po.Path)
po.Yaml = string(content)
......
......@@ -34,7 +34,7 @@ func (s *TextService) Get(id int) (text model.ZdText, dirs []model.Dir) {
func (s *TextService) Save(text *model.ZdText) (err error) {
text.Folder = serverUtils.DealWithPathSepRight(text.Folder)
text.Path = vari.WorkDir + text.Folder + serverUtils.AddExt(text.FileName, ".txt")
text.ReferName = service.PathToName(text.Path, constant.ResDirYaml)
text.ReferName = service.PathToName(text.Path, constant.ResDirYaml, constant.ResTypeText)
if text.ID == 0 {
err = s.Create(text)
......@@ -109,9 +109,9 @@ func (s *TextService) SyncToDB(file model.ResFile) (err error) {
FileName: fileUtils.GetFileName(file.Path),
}
if strings.Index(text.Path, constant.ResDirYaml) > -1 {
text.ReferName = service.PathToName(text.Path, constant.ResDirYaml)
text.ReferName = service.PathToName(text.Path, constant.ResDirYaml, constant.ResTypeText)
} else {
text.ReferName = service.PathToName(text.Path, constant.ResDirUsers)
text.ReferName = service.PathToName(text.Path, constant.ResDirUsers, constant.ResTypeText)
}
text.Content = fileUtils.ReadFile(file.Path)
......
......@@ -35,7 +35,6 @@ func LoadRes(resType string) (res map[string][]model.ResFile, nameWidth, titleWi
for _, item := range res[key] {
pth := item.Path
fileExt := path.Ext(pth)
name := PathToName(pth, key)
isArticleFiles := false
var title, desc, tp string
......@@ -51,12 +50,12 @@ func LoadRes(resType string) (res map[string][]model.ResFile, nameWidth, titleWi
}
}
item.ReferName = name
item.ReferName = PathToName(pth, key, tp)
item.Title = title
item.Desc = desc
item.ResType = tp
lent := runewidth.StringWidth(name)
lent := runewidth.StringWidth(item.ReferName)
if lent > nameWidth {
nameWidth = lent
}
......@@ -199,18 +198,23 @@ func ReadExcelInfo(path string) (title, desc, resType string) {
}
func ReadTextInfo(path, key string) (title, desc, resType string) {
title = PathToName(path, key)
title = PathToName(path, key, constant.ResTypeText)
desc = i118Utils.I118Prt.Sprintf("text_data")
resType = constant.ResTypeText
return
}
func PathToName(path, key string) string {
name := strings.ReplaceAll(path, constant.PthSep,".")
sep := "." + key + "."
name = name[strings.Index(name, sep)+len(sep):]
func PathToName(path, key, tp string) string {
nameSep := "/"
if tp != constant.ResTypeText && tp != constant.ResTypeYaml && tp != constant.ResTypeConfig {
nameSep = "."
}
path = strings.ReplaceAll(path, constant.PthSep, nameSep)
sep := nameSep + key + nameSep
name := path[strings.Index(path, sep)+len(sep):]
if key == constant.ResDirData { // remove .xlsx postfix
name = name[:strings.LastIndex(name, ".")]
name = name[:strings.LastIndex(name, nameSep)]
}
return name
......
无法预览此类型文件
title: 内容被引用
title: 被引用测试
desc:
author: zentao
version: 1.0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册