Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
5934f5d0a7
2 changed files with 88 additions and 0 deletions
|
@ -896,6 +896,49 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
}
|
||||
}
|
||||
|
||||
// 导出自定义排序
|
||||
sortPath := filepath.Join(util.DataDir, box.ID, ".siyuan", "sort.json")
|
||||
fullSortIDs := map[string]int{}
|
||||
sortIDs := map[string]int{}
|
||||
var sortData []byte
|
||||
var sortErr error
|
||||
if gulu.File.IsExist(sortPath) {
|
||||
sortData, sortErr = filelock.NoLockFileRead(sortPath)
|
||||
if nil != sortErr {
|
||||
logging.LogErrorf("read sort conf failed: %s", sortErr)
|
||||
}
|
||||
|
||||
if sortErr = gulu.JSON.UnmarshalJSON(sortData, &fullSortIDs); nil != sortErr {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", sortErr)
|
||||
}
|
||||
|
||||
if 0 < len(fullSortIDs) {
|
||||
for _, tree := range trees {
|
||||
if v, ok := fullSortIDs[tree.ID]; ok {
|
||||
sortIDs[tree.ID] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if 0 < len(sortIDs) {
|
||||
sortData, sortErr = gulu.JSON.MarshalJSON(sortIDs)
|
||||
if nil != sortErr {
|
||||
logging.LogErrorf("marshal sort conf failed: %s", sortErr)
|
||||
}
|
||||
if 0 < len(sortData) {
|
||||
confDir := filepath.Join(exportFolder, ".siyuan")
|
||||
if mkdirErr := os.MkdirAll(confDir, 0755); nil != mkdirErr {
|
||||
logging.LogErrorf("create export conf folder [%s] failed: %s", confDir, mkdirErr)
|
||||
} else {
|
||||
sortPath = filepath.Join(confDir, "sort.json")
|
||||
if writeErr := os.WriteFile(sortPath, sortData, 0644); nil != writeErr {
|
||||
logging.LogErrorf("write sort conf failed: %s", writeErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zipPath = exportFolder + ".sy.zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
|
|
|
@ -174,6 +174,51 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// 合并 sort.json
|
||||
fullSortIDs := map[string]int{}
|
||||
sortIDs := map[string]int{}
|
||||
var sortData []byte
|
||||
var sortErr error
|
||||
sortPath := filepath.Join(unzipRootPath, ".siyuan", "sort.json")
|
||||
if gulu.File.IsExist(sortPath) {
|
||||
sortData, sortErr = filelock.NoLockFileRead(sortPath)
|
||||
if nil != sortErr {
|
||||
logging.LogErrorf("read import sort conf failed: %s", sortErr)
|
||||
}
|
||||
|
||||
if sortErr = gulu.JSON.UnmarshalJSON(sortData, &sortIDs); nil != sortErr {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", sortErr)
|
||||
}
|
||||
|
||||
sortPath = filepath.Join(util.DataDir, boxID, ".siyuan", "sort.json")
|
||||
if gulu.File.IsExist(sortPath) {
|
||||
sortData, sortErr = filelock.NoLockFileRead(sortPath)
|
||||
if nil != sortErr {
|
||||
logging.LogErrorf("read box sort conf failed: %s", sortErr)
|
||||
}
|
||||
|
||||
if sortErr = gulu.JSON.UnmarshalJSON(sortData, &fullSortIDs); nil != sortErr {
|
||||
logging.LogErrorf("unmarshal box sort conf failed: %s", sortErr)
|
||||
}
|
||||
}
|
||||
|
||||
for oldID, sort := range sortIDs {
|
||||
if newID := blockIDs[oldID]; "" != newID {
|
||||
fullSortIDs[newID] = sort
|
||||
}
|
||||
}
|
||||
|
||||
sortData, sortErr = gulu.JSON.MarshalJSON(fullSortIDs)
|
||||
if nil != sortErr {
|
||||
logging.LogErrorf("marshal box sort conf failed: %s", sortErr)
|
||||
} else {
|
||||
sortErr = filelock.NoLockFileWrite(sortPath, sortData)
|
||||
if nil != sortErr {
|
||||
logging.LogErrorf("write box sort conf failed: %s", sortErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重命名文件路径
|
||||
renamePaths := map[string]string{}
|
||||
filepath.Walk(unzipRootPath, func(path string, info fs.FileInfo, err error) error {
|
||||
|
|
Loading…
Add table
Reference in a new issue